Reputation: 15002
Say, The put method can return includeExtraTitle field by the given param
However, Is it a good idea to add param on PUT
method?
Is this a good practice?
@PutMapping(value = "/articles/{articleId}")
Article put(@RequestParam(value = "includeExtraTitle", defaultValue = "false") boolean includeExtraTitle)
Upvotes: 0
Views: 530
Reputation: 57204
/articles/{articleId}?includeExtraTitle=true
is a perfectly fine identifier for a resource.
PUT
is a method in the uniform interface, so applying PUT semantics to this resource is fine (if you decide that isn't supported, you would respond with 405 Method Not Allowed).
/articles/{articleId}
/articles/{articleId}?includeExtraTitle=true
/articles/{articleId}?includeExtraTitle=false
You should understand that, from the point of view of the client, these are identifiers for different resources. PUT /articles/{articleId}?includeExtraTitle=false
won't invalidate the client's locally cached copy of /articles/{articleId}
, because the identifiers don't match.
The fact that these three resources happen to use the same "endpoint" is an accident of your implementation, and hidden from clients behind the uniform interface.
It's perfectly normal, though not necessarily common, for a single resource to have multiple representations. So check that your use case isn't a better fit for varying the content-type, rather than varying the URI.
Upvotes: 1
Reputation: 1923
Yes, It's an absolutely good approach.
Adding parameters for HTTP request types such as POST, PUT etc is exactly fine and recommended approach.
Upvotes: 1