- Building RESTful Web Services with PHP 7
- Haafiz Waheed ud din Ahmad
- 96字
- 2021-07-03 00:02:20
Reading a comment
- Request: GET /posts/1/comment/1 HTTP/1.1 or GET /comment/1 HTTP/1.1
The second one seems more reasonable as in that one only needs to have a comment's ID without worrying about the post ID of that comment. And since a comment's ID is unique, we don't need to have the post's ID to get the comment. So, we will proceed with the second URL that is GET /comment/1 HTTP/1.1.
- Response:
{id:1, post_id:1, comment:"An Awesome Post", link: "/comments/1"}
- Response code: 200 OK
Since any comment can only exist against some post, the response includes post_id as well.