Home What's the proper REST API url for updating sub-resources?
Reply: 1

What's the proper REST API url for updating sub-resources?

Meysam
1#
Meysam Published in 2017-12-07 17:45:09Z

It seems to be a good practice to follow this rule:

If a resource is related to another resource use subresources.

Example:

GET /users/711/posts ====> Returns a list of posts for user 711
GET /users/711/posts/4 ====> Returns post #4 for user 711

Now what if I want to update a sub-resource? Should I still use this relation? Which of the following two approaches is more preferred/standard?

PUT /users/711/posts/4 =====> Update post #4
PUT /posts/4

Cassio Mazzochi Molin
2#
Cassio Mazzochi Molin Reply to 2017-12-07 20:50:23Z

Keep it consistent.

/users/711/posts/4 is a URI that identifies/locates a resource in your server. The same identifier/locator should be used to get a representation, delete and replace the state of the resource.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.353233 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO