POST /api/v1/articles • HTTP 201 Created

Simple POST Request (Create New Record) — Request & Response Example

Illustrates how an HTTP POST request works when creating a new resource. The client sends a request body in JSON format, and the server assigns an ID and returns status 201 Created.

1. HTTP Client Request (POST)

POST /api/v1/articles HTTP/1.1
{
  "Content-Type": "application/json",
  "Accept": "application/json"
}

{
  "title": "How APIs Power the Modern Web",
  "slug": "how-apis-power-web",
  "category": "Engineering",
  "is_published": true,
  "tags": [
    "api",
    "http",
    "rest"
  ]
}

2. Server JSON Response (HTTP 201 Created)

{
  "id": 1092,
  "title": "How APIs Power the Modern Web",
  "slug": "how-apis-power-web",
  "category": "Engineering",
  "is_published": true,
  "tags": [
    "api",
    "http",
    "rest"
  ],
  "created_at": "2026-10-06T12:45:00.000Z",
  "status": "published"
}

Copy-Paste Code Snippets (cURL, JavaScript Fetch, Python, Node.js)

curl -X POST "https://cometflow.space/api/v1/articles" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "How APIs Power the Modern Web",
    "slug": "how-apis-power-web",
    "category": "Engineering",
    "is_published": true,
    "tags": ["api", "http", "rest"]
  }'
fetch('https://cometflow.space/api/v1/articles', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    title: 'How APIs Power the Modern Web',
    slug: 'how-apis-power-web',
    category: 'Engineering',
    is_published: true,
    tags: ['api', 'http', 'rest']
  })
})
  .then(res => res.json())
  .then(createdArticle => console.log(createdArticle));
import requests

payload = {
    "title": "How APIs Power the Modern Web",
    "slug": "how-apis-power-web",
    "category": "Engineering",
    "is_published": True,
    "tags": ["api", "http", "rest"]
}

response = requests.post(
    "https://cometflow.space/api/v1/articles",
    json=payload
)
print(response.status_code) # 201
print(response.json())

How This API Call Works Step-by-Step

  1. 1. HTTP POST Method: Signals to the server that new information is being submitted for insertion.
  2. 2. Content-Type Header: Informs the server that the incoming body payload is formatted as application/json.
  3. 3. Database Insertion: The backend validates required fields and writes a new row to the database table.
  4. 4. 201 Created Response: The server returns the generated ID (1092) and a Location header pointing to the new item.

Backend API Functions: The API function createArticle(req, res) runs schema validation (e.g. using Zod or Joi) on req.body, generates a unique ID, writes to the DB, and dispatches the 201 Created response.

Frequently Asked Questions

Why does POST return 201 instead of 200?

HTTP status 201 explicitly specifies "Created", informing the client that a new resource was successfully created as a direct consequence of the request.