Reputation: 3832
Im working on a REST API, it respond to request with JSON data. (Content-type: application/JSON). But is there any right or wrong regarding the Content-type of my POST and GET request. Should this be JSON or url-encoded, or is it irrelevant?
Upvotes: 7
Views: 9088
Reputation: 3709
Only POST and PUT requests send a body and therefore have a request content type. GET requests do not have a content type.
If your request conceptually creates/updates a resource, use a POST or PUT method and accept JSON as the request body. (If you want to accept application/x-www-form-urlencoded
data as well as (or instead of) JSON, that's up to you - it just depends on your requirements, it's not a matter of 'right' or 'wrong' here).
If your request is accessing/querying a resource, use GET and encode any relevant parameters in the url (either as a query string or in the url path itself).
Side note: 'RESTful' is often used incorrectly to refer to all sorts of things. It's worth doing some reading to fully grasp the concepts (maybe start with Wikipedia http://en.wikipedia.org/wiki/Representational_state_transfer and follow references from there)
Upvotes: 9