Compile the code, run it, and use curl to check the result. First, let's check the traditional JSON format:
$ curl --header "Content-Type: application/json" --request POST \
--data '{"distribution": "uniform", "parameters": {"start": -100, "end": 100}}' \
"http://localhost:8080/random?format=json"
This will return a JSON response that we've seen before: {"value":-19.0}. The next request will return a CBOR value:
$ curl --header "Content-Type: application/json" --request POST \
--data '{"distribution": "uniform", "parameters": {"start": -100, "end": 100}}' \
"http://localhost:8080/random?format=cbor"
This command won't print a response to the console, because it's in binary format. You'll see the following warning message:
Warning: Binary output can mess up your terminal. Use "--output -" to tell
Warning: curl to output it to your terminal anyway, or consider "--output
Warning: <FILE>" to save to a file.
Let's try to request a response in XML format:
$ curl --header "Content-Type: application/json" --request POST \
--data '{"distribution": "uniform", "parameters": {"start": -100, "end": 100}}' \
"http://localhost:8080/random?format=xml"
This has worked correctly; it printed unsupported format xml to indicate that it doesn't support XML format. Let's now move on to discussing transcoding serde values and looking at why XML isn't a format that's widely supported by serde.