Zum Inhalt springen
uencoder

REST API Design Referenz

Referenz für REST architectural style: resources, HTTP Methoden, status codes, und best practices.

REST Constraints

REST (Representational State Transfer) is defined by six constraints: client-server, stateless, cacheable, uniform interface, layered system, and code-on-demand (optional). The uniform interface consists of resource identification, resource manipulation through representations, self-descriptive messages, and HATEOAS. Resources are identified by URIs and manipulated via HTTP methods. Statelessness requires all request context in the request itself. These constraints enable scalability and simplicity.

stateless
No server session
all context in request
uniform interface
Standard HTTP methods
GET, POST, PUT, DELETE
HATEOAS
Hypermedia links
discover actions

Design Best Practices

Use nouns for resource paths (/users, /orders/{id}), not verbs. HTTP methods map to CRUD: GET (read), POST (create), PUT/PATCH (update), DELETE (remove). Status codes indicate outcomes: 2xx success, 3xx redirect, 4xx client error, 5xx server error. Versioning via URI prefix (/v1/) or Accept header. Pagination, filtering, and sorting via query parameters. Consistent error format with machine-readable codes. Idempotency for PUT and DELETE.

nouns not verbs
/users not /getUsers
resource-oriented
methods
GET/POST/PUT/DELETE
CRUD mapping
versioning
/v1/ or Accept header
evolve safely

Verwandte Tools

参考链接