๐Ÿ“ API

REST API Design Principles

P
Author
PyLand Team
๐Ÿ“…
Published
30.06.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
275
๐ŸŒณ
Level
Advanced

Covered topics: 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

๐Ÿ“

API Keys: What They Are and How to Use Them

Most public APIs require an API key โ€” a unique string that identifies you as...

๐Ÿ“… 08.05.2026 ๐Ÿ‘๏ธ 374
๐Ÿ“

The requests Library: HTTP Requests from Python

requests is the most downloaded Python library in the world โ€” over 300 million downloads...

๐Ÿ“… 08.05.2026 ๐Ÿ‘๏ธ 342
๐Ÿ“

How to Read API Documentation

API documentation is a developer's primary tool. Knowing how to read it matters more than...

๐Ÿ“… 08.05.2026 ๐Ÿ‘๏ธ 359
๐ŸŽ“ Continue learning

Courses that cover this material

Visit the course to apply this material in practice.

FastAPI: From First Route to an AI-Powered Site Open course curriculum