Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

rest - Including Id in URI for PUT requests

I was reading some documents about the appropriate use of URI's using rest services and I came across an example for basic GET .. DELETE requests.

The example uri's were:

Get all users

GET http://mydomain.org/api/users

Get specific user

GET http://mydomain.org/api/users/1

Update user

PUT http://mydomain.org/api/users/1

DELETE user

DELETE http://mydomain.org/api/users/1

A user resource would be either JSON or XML in the form of:

{
    Id: 1,
    FirstName: 'John',
    LastName: 'Doe'
}

My question is this. To maintain REST principles, is it required to include the id of the resource within the URI for PUT requests?

question from:https://stackoverflow.com/questions/9265286/including-id-in-uri-for-put-requests

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The PUT method requests that the state of the target resource be created or replaced with the state defined by the representation enclosed in the request message payload.

You want to PUT a resource to the same URI you intend to GET it from.

RFC 72314.3.4 PUT


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...