What is the best way to design calls of post and comments in a rest api?

So, currently I have two models: Post and Comment. Where a post can have multiple comments. I have an endpoint named Posts and an endpoint named Comments that is called to retrieve comments of a post. currently I can call /posts to retrieve all posts, or call /comments to retrieve all comments. But how do the url's need to look like? Which of the following is the best choice: Get all comments of a post: Method 1 GET /comments?post_id={post_id} Method 2 GET /posts/{post_id}/comments Create new comments: Method 1 POST /comments Method 2 POST /post/{post_id}/comments I don't think this information matters but I'm using Django + DRF.

Jun 14, 2025 - 03:00
 0

So, currently I have two models: Post and Comment. Where a post can have multiple comments.

I have an endpoint named Posts and an endpoint named Comments that is called to retrieve comments of a post.

currently I can call /posts to retrieve all posts, or call /comments to retrieve all comments.

But how do the url's need to look like? Which of the following is the best choice:

Get all comments of a post:

Method 1

GET /comments?post_id={post_id}

Method 2

GET /posts/{post_id}/comments

Create new comments:

Method 1

POST /comments

Method 2

POST /post/{post_id}/comments

I don't think this information matters but I'm using Django + DRF.