Clayton A. Alves Clayton A. Alves - 23 days ago 9
JSON Question

What is the standard practice to serve a REST API request, based on requester format?

In my REST API, I have an

/items/
endpoint which returns a list of items.

The user of my API may request the items in different formats (json, xml, html).

What is the recommended way to provide a json response:


  • make an
    /items.json
    endpoint ?

  • make an
    /items/json
    endpoint ?

  • or serve it based on user's request header
    Content-Type


Answer Source

Serve it based on the Accept request header. This is a standard practice called content type negotiation.