|
|
|
|
|
by mamoriamohit
1396 days ago
|
|
This is good for fetching a single item. What if you want to list resources? Eg. List all comments of a blog? It has to be GET /blog/:blogid/comments Then, how about creating a new comment? It'll be POST /blog/:blogid/comments When both of these have the blog's hierarchy in the URL, should we take it away when fetching a single item? Or the stay consistent, we should simply do: /blog/:blogid/comments/:commentid It's hard. |
|
You're just asking for one of the most basic features in resource-oriented architectures: query a collection resource with a filter predicate and possibly pagination.
GET /comments?blog=<blogId>
> Then, how about creating a new comment?
Same thing: just POST it to /comments with a relevant request document, such as
{"blog":<blogId>,"comment":<blah blah blah>}
Your POST request then receives a response with a link to the newly-created comment resource, and that's it.
> When both of these have the blog's hierarchy in the URL, should we take it away when fetching a single item?
Resources do not have a hierarchy per se. You've just been passing request parameters through the path. That's it.
> It's hard.
Not really. It's a matter of understanding that resource-based architectures just deal with resources, and not resource hierarchies which don't really exist per se.
What you mean by hierarchy is actually just passing parameters through the path, but those parameters can be passed elsewhere.