Meysam
Meysam

Reputation: 18137

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

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

Upvotes: 0

Views: 221

Answers (1)

cassiomolin
cassiomolin

Reputation: 130887

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.

Upvotes: 2

Related Questions