Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST how to handle query parameters when put to resource?

Tags:

rest

html

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.

like image 945
Peter Hoffmann Avatar asked Dec 08 '22 09:12

Peter Hoffmann


1 Answers

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.

like image 51
Peter Hilton Avatar answered Jan 08 '23 21:01

Peter Hilton