Question

I have a REST data service where I want to allow the users to create new items with HTTP PUT using different formats like json,xml,csv. I'm unsure how to best handle the format specification in the url:

PUT /ressource/ID/json
PUT /ressource/ID/xml

or

PUT /ressource/ID?format=json
PUT /ressource/ID?format=xml

So what is the best way to specify a format indicator?

If I specify the format with an query parameter and want to do a PUT how can I do this with curl?

curl -T test/data.json -d "format=json"  http://localhost:5000/resource/33

does not work.

curl -T test/data.json http://localhost:5000/update?format=json

works, but I would rather let curl build the query parameters instead of adding them by myself.

Was it helpful?

Solution

A general principle of RESTful web services is to use the features built-in to HTTP, when applicable. In this case, you can indicate the format of your PUT request's content by setting the Content-Type header to application/json or application/xml.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top