An example of how to perform content negotiation using the res.format()
method
in an Opine server.
Run this example using:
deno run --allow-net --allow-read ./examples/content-negotiation/index.ts
if have the repo cloned locally OR
deno run --allow-net --allow-read https://raw.githubusercontent.com/cmorten/opine/main/examples/content-negotiation/index.ts
if you don't!
Then try:
- Opening http://localhost:3000/ in a browser - should see a HTML list.
curl -X GET http://localhost:3000 -H 'Accept: text/plain'
- should see a plaintext list.curl -X GET http://localhost:3000 -H 'Accept: application/json'
- should see a JSON object.
You can also try the above on the /users
route.