📝 API

REST API Design Principles

P
Author
Pyland
📅
Published
30.06.2026
⏱️
Reading time
1 min
👁️
Views
68
🌳
Level
Advanced

Охватываемые темы: Resources and URLs, HTTP methods, Nested resources, Response codes.

Resources and URLs

A URL should represent a resource (a noun), not an action:

# Bad (action in the URL)
GET /getTasks
POST /createTask
DELETE /deleteTask/1

# Good (resource + HTTP method = action)
GET /tasks
POST /tasks
DELETE /tasks/1

HTTP methods

Method Action Idempotent
GET Retrieve Yes
POST Create No
PUT Replace entirely Yes
PATCH Partial update Yes
DELETE Remove Yes

Nested resources

GET /projects/5/tasks           # tasks of project 5
POST /projects/5/tasks          # create a task in project 5
GET /projects/5/tasks/10        # a specific task within a project

Response codes

200 OK              — success (GET, PUT, PATCH)
201 Created         — created (POST)
204 No Content      — deleted (DELETE)
400 Bad Request     — malformed request
401 Unauthorized    — not authenticated
403 Forbidden       — insufficient permissions
404 Not Found       — resource not found
422 Unprocessable   — validation error
500 Server Error    — server-side error

Filtering, sorting, pagination

GET /tasks?status=todo              # filtering
GET /tasks?ordering=-created_at     # sorting
GET /tasks?page=2&page_size=20      # pagination
GET /tasks?search=important+task    # search

Response format

// List
{
  "count": 42,
  "next": "http://api.example.com/tasks/?page=2",
  "previous": null,
  "results": [
    {"id": 1, "title": "Task", "status": "todo"}
  ]
}

// Error
{
  "error": "validation_error",
  "message": "Title is required",
  "field": "title"
}

Versioning

/api/v1/tasks/    # version in the URL (most common approach)
/api/v2/tasks/

# Or via header:
Accept: application/vnd.myapi.v1+json

Your reaction to the article

💬 Comments (0)

🔐 Sign in to leave a comment
🚪 Login
💭

No comments yet

Be the first to share your opinion about this article!

🔗 Similar

Similar articles

Continue learning with these materials

📝

Middleware and CORS in FastAPI

Allows browser clients to make requests to an API from a different domain.

📅 30.06.2026 👁️ 87
📝

HTTPException in FastAPI

Охватываемые темы: Basic Usage, Status Codes, Error Details, Custom Headers.

📅 30.06.2026 👁️ 91
📝

Dependency Injection in FastAPI

Depends — FastAPI's dependency injection system for reusing code across endpoints.

📅 30.06.2026 👁️ 83

Did you like the article?

Subscribe to our updates and receive new articles first. Grow with PyLand!