REST, how to handle request parameters when transferring to a resource?

I have a REST data service where I want to allow users to create new elements using HTTP PUT, using different formats such as json, xml, csv. I'm not sure how best to 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 a format with a request parameter and want to do 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 query parameters, rather than add them myself.

+4
source share
1 answer

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

+15
source

Source: https://habr.com/ru/post/1276591/


All Articles