Reputation: 942
I'm working a RESTFul API and have a POST method that will allow either JSON or CSV body content.
What is best way to handle this? Should URL routing/parameters be used (such as /resource/json
or /resource/?type=json
), or through headers (so URL would just be /resource
and a header would specify json or csv)?
Upvotes: 1
Views: 3277
Reputation: 41428
The proper way according to W3C (https://www.w3.org/Protocols/rfc1341/4_Content-Type.html) is to use the Content Type header to specify the correct type.
Content-Type: application/json
Content-Type: text/csv
Avoid using url params. While this is not 'non-restful' it's not the recommended method and smells of amateur hour. Even worse is creating a new 'resource' which is just a representation of an existing resource.
Upvotes: 1