API Reference
This document provides details on the available REST API endpoints for the Article service.
The base URL for the API in the default local setup is http://localhost:9090.
Articles
List Articles
Fetches a paginated list of articles.
- Endpoint:
GET /articles - Method:
GET
Query Parameters
| Parameter | Type | Description |
|---|---|---|
num |
integer | The number of articles to return per page. Default: 10. |
cursor |
string | The cursor for the next page of results, obtained from the X-Cursor header of the previous response. |
Success Response
- Code:
200 OK - Headers:
X-Cursor:string- The cursor to use to fetch the next page of results. This header is omitted if there are no more results.
- Content: An array of article objects.
Example Request:
curl -i http://localhost:9090/articles?num=2
Example Response:
HTTP/1.1 200 OK
Content-Type: application/json; charset=UTF-8
X-Cursor: MjAxNy0wNS0xOFQxMzo1MDoxOS4wMDBa
Date: ...
Content-Length: ...
[
{
"id": 1,
"title": "Makan Ayam",
"content": "<p>...",
"author": {
"id": 1,
"name": "Iman Tumorang",
"created_at": "2017-05-18T13:50:19Z",
"updated_at": "2017-05-18T13:50:19Z"
},
"updated_at": "2017-05-18T13:50:19Z",
"created_at": "2017-05-18T13:50:19Z"
},
{
"id": 2,
"title": "Makan Ikan",
"content": "<h1>...",
"author": {
"id": 1,
"name": "Iman Tumorang",
"created_at": "2017-05-18T13:50:19Z",
"updated_at": "2017-05-18T13:50:19Z"
},
"updated_at": "2017-05-18T13:50:19Z",
"created_at": "2017-05-18T13:50:19Z"
}
]
Create Article
Creates a new article.
- Endpoint:
POST /articles - Method:
POST
Request Body
A JSON object representing the article to be created.
| Field | Type | Description | Required |
|---|---|---|---|
title |
string | The title of the article. | Yes |
content |
string | The content of the article. | Yes |
author |
object | The author of the article. | Yes |
author.id |
integer | The ID of the author. | Yes |
Success Response
- Code:
201-Created - Content: The newly created article object, including its server-assigned
id.
Example Request:
curl -X POST -H "Content-Type: application/json" \
-d '{"title":"New Article Title","content":"This is the content.","author":{"id":1}}' \
http://localhost:9090/articles
Error Responses
400 Bad Request: If the request body is invalid (e.g., missing required fields).409 Conflict: If an article with the same title already exists.422 Unprocessable Entity: If the JSON body cannot be parsed.
Get Article by ID
Retrieves a single article by its ID.
- Endpoint:
GET /articles/:id - Method:
GET
URL Parameters
| Parameter | Type | Description |
|---|---|---|
id |
integer | The ID of the article to retrieve. |
Success Response
- Code:
200 OK - Content: The requested article object.
Example Request:
curl http://localhost:9090/articles/1
Error Responses
404 Not Found: If no article with the specified ID exists.
Delete Article
Deletes a single article by its ID.
- Endpoint:
DELETE /articles/:id - Method:
DELETE
URL Parameters
| Parameter | Type | Description |
|---|---|---|
id |
integer | The ID of the article to delete. |
Success Response
- Code:
24 No Content
Example Request:
curl -X DELETE http://localhost:9090/articles/3
Error Responses
404 Not Found: If no article with the specified ID exists.