Reputation: 2481
I create rest api and I have a POST which has many comments. What is the better url to get post comments
//Get all comments of a post
GET /posts/{postId}/comments
or
GET /comments/{postId}
//Create new comment
POST /posts/{postId}/comments
or
POST /comments/{postId}
A POST has many CATERORY and a CATEGORY can belong to many POST How I can create a post with ,for example, 3 categories. And how I can connect a specific existing post to a specific existing category
Upvotes: 1
Views: 54
Reputation: 57299
What is the better url to get post comments
REST doesn't care about your spelling conventions for URI -- that's part of the point. So you should use whatever spellings are consistent with your local conventions.
Depending on your API and representations, it may be useful to think about relative references in your hierarchy. For instance, if your base URI is /posts/{postId}/abstract
, then the relative reference ../comments
can be resolved to /posts/{postId}/comments
; but there is no analogous trick to get you from /abstracts/{postId}
to /comments/{postId}
.
- How I can create a post with ,for example, 3 categories
- how I can connect a specific existing post to a specific existing category
How would you do it with a web site? Having done that, how would you make the web site machine readable?
Upvotes: 1