One URL, many formats

With content negotiation, a client tells the server in the Accept header which formats it understands and how much it prefers each one (the q weight from 0 to 1). The route /negotiation/planets reads the header and returns a Response in the best matching format, or 406 Not Acceptable. It also sends Vary: Accept, so caches keep one copy per format.

Pick a preset or write your own header. The request is sent with fetch(), as browsers always send their own Accept header when you follow a link.

From the command line

curl -H "Accept: text/html" https://expo.jeasx.dev/negotiation/planets
curl -H "Accept: application/json" https://expo.jeasx.dev/negotiation/planets
curl -H "Accept: text/csv" https://expo.jeasx.dev/negotiation/planets
curl -H "Accept: text/plain" https://expo.jeasx.dev/negotiation/planets