API reference
every endpoint, explained
Parameters, request examples and responses for users, posts, comments and todos.
Base URLhttps://gorest.co.in/public/v2Comments
A comment belongs to a post. Reading comments needs no token. Creating, updating and deleting do, and those records are visible only to your token.
The comment object
- idinteger
- Unique identifier.
- post_idinteger
- The id of the post.
- namestring
- Name of the commenter. Up to 200 characters.
- emailstring
- Email of the commenter. Must be valid.
- bodystring
- Up to 500 characters.
{
"id": 5301,
"post_id": 2410,
"name": "Pranav Kapoor",
"email": "pranav.kapoor@example.com",
"body": "Good write up. Did the reset time change on the old setup too?"
}List comments
GET/public/v2/commentsReturns a page of comments, the most recently changed first. Any field can be a filter.
Query parameters
- pageintegeroptional
- Page number. Starts at 1.
- per_pageintegeroptional
- Results per page, 1 to 100. Any other value gives 10.
- idintegeroptional
- Exact id.
- post_idintegeroptional
- Comments on this post.
- namestringoptional
- Part of the name. Not case sensitive.
- emailstringoptional
- Part of the email. Not case sensitive.
- bodystringoptional
- Part of the body. Not case sensitive.
The pagination headers come with the list. See Pagination below.
curl "https://gorest.co.in/public/v2/comments?page=1&per_page=10"
[
{
"id": 5301,
"post_id": 2410,
"name": "Pranav Kapoor",
"email": "pranav.kapoor@example.com",
"body": "Good write up. Did the reset time change on the old setup too?"
}
]Get a comment
GET/public/v2/comments/:idReturns one comment. A wrong id gives 404.
Path parameters
- idintegerrequired
- The id of the record.
curl "https://gorest.co.in/public/v2/comments/5301"
{
"id": 5301,
"post_id": 2410,
"name": "Pranav Kapoor",
"email": "pranav.kapoor@example.com",
"body": "Good write up. Did the reset time change on the old setup too?"
}Create a comment
POST/public/v2/commentsNeeds a token. Returns 201 with the new comment and a Location header, or 422 with a list of field errors. The post must exist.
Body parameters
- post_idintegerrequired
- The id of an existing post.
- namestringrequired
- Up to 200 characters.
- emailstringrequired
- Valid email, up to 200 characters.
- bodystringrequired
- Up to 500 characters.
Only your token can see the new record.
curl -X POST "https://gorest.co.in/public/v2/comments" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"post_id":2410,"name":"Pranav Kapoor","email":"pranav.kapoor@example.com","body":"Good write up. Did the reset time change on the old setup too?"}'{
"id": 5301,
"post_id": 2410,
"name": "Pranav Kapoor",
"email": "pranav.kapoor@example.com",
"body": "Good write up. Did the reset time change on the old setup too?"
}Update a comment
PATCH/public/v2/comments/:idNeeds a token. Changes only the fields you send and returns the comment. PUT does the same as PATCH. A record you cannot see gives 404.
Body parameters
- post_idintegeroptional
- The id of an existing post.
- namestringoptional
- Up to 200 characters.
- emailstringoptional
- Valid email, up to 200 characters.
- bodystringoptional
- Up to 500 characters.
curl -X PATCH "https://gorest.co.in/public/v2/comments/5301" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"body":"Thanks, that answers it."}'{
"id": 5301,
"post_id": 2410,
"name": "Pranav Kapoor",
"email": "pranav.kapoor@example.com",
"body": "Thanks, that answers it."
}Delete a comment
DELETE/public/v2/comments/:idNeeds a token. Returns 204 with an empty body.
Path parameters
- idintegerrequired
- The id of the record.
If the table has fewer than 100 seeded records, the delete is refused with 422.
curl -X DELETE "https://gorest.co.in/public/v2/comments/5301" \ -H "Authorization: Bearer YOUR_TOKEN"
(empty body)
List the comments on a post
GET/public/v2/posts/:id/commentsThe same as the list above with post_id set from the path. Paging and the other filters work too.
Path parameters
- idintegerrequired
- The id of the post.
curl "https://gorest.co.in/public/v2/posts/2410/comments"
[
{
"id": 5301,
"post_id": 2410,
"name": "Pranav Kapoor",
"email": "pranav.kapoor@example.com",
"body": "Good write up. Did the reset time change on the old setup too?"
}
]Add a comment to a post
POST/public/v2/posts/:id/commentsNeeds a token. The post id comes from the path, even if the body has another one. A missing post gives 422 with "must exist".
Body parameters
- namestringrequired
- Up to 200 characters.
- emailstringrequired
- Valid email.
- bodystringrequired
- Up to 500 characters.
curl -X POST "https://gorest.co.in/public/v2/posts/2410/comments" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name":"Pranav Kapoor","email":"pranav.kapoor@example.com","body":"Good write up. Did the reset time change on the old setup too?"}'{
"id": 5301,
"post_id": 2410,
"name": "Pranav Kapoor",
"email": "pranav.kapoor@example.com",
"body": "Good write up. Did the reset time change on the old setup too?"
}Authentication
Reading needs no token. Writing (POST, PATCH, PUT, DELETE) needs one. Make a token on the tokens page after you log in, and send it in one of two ways.
- Authorization: Bearer YOUR_TOKEN
- A request header. This is the better way.
- ?access-token=YOUR_TOKEN
- A query parameter, for quick tests in the browser.
A write without a token gives 401. A token that is wrong gives 401 "Invalid token", and an expired one gives 401 "Token expired". A token can only see the seeded records and its own.
Pagination
Lists give 10 records a page. Use page and per_page (1 to 100) to change that. Details come in the response headers.
- X-Pagination-Total
- Total records that match.
- X-Pagination-Pages
- Total pages.
- X-Pagination-Page
- The current page.
- X-Pagination-Limit
- Records on a page.
- X-Links-Previous
- Full URL of the previous page. Empty on page 1.
- X-Links-Current
- Full URL of this page.
- X-Links-Next
- Full URL of the next page. Empty on the last page.
Rate limits
Each token can send 300 requests a minute by default. You can set it from 1 to 600 on the tokens page. Reads without a token have no limit. Calls with a token carry these headers. Past the limit you get 429 "Too many requests".
- X-RateLimit-Limit
- Requests a minute allowed for this token.
- X-RateLimit-Remaining
- Requests left now.
- X-RateLimit-Reset
- Seconds until you get more requests.
Errors and status codes
- 200 OK
- The request worked. The record or list is in the body.
- 201 Created
- A record was made. The Location header has its URL.
- 204 No Content
- A delete worked. The body is empty.
- 304 Not Modified
- Your cached copy (If-None-Match with the ETag) is still good.
- 400 Bad Request
- A parameter is not valid text.
- 401 Unauthorized
- The token is missing, wrong or expired.
- 404 Not Found
- No such record, or it belongs to another token.
- 422 Unprocessable
- A field failed a check. The body is a list of field and message.
- 429 Too Many Requests
- The rate limit is used up.
- 500 Server Error
- A fault on our side.
[
{ "field": "email", "message": "has already been taken" }
]Format and testing
- ?delay=1500
- On a GET, waits that many milliseconds first. The most is 5000. The answer has X-Simulated-Delay-Ms.
- ?force_status=503
- Answers with that code. Allowed: 400, 401, 403, 404, 405, 415, 422, 429, 500 and 503.
- .json or .xml
- Add it to the path, or set the Accept header, to choose JSON or XML. JSON is the default.
Want to try a call now? Open the REST console.