简体   繁体   中英

REST how to handle query parameters when put to resource?

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM