Junior — Middle
What principles and characteristics must an API adhere to in order to be considered RESTful?
sobes.tech AI
Answer from AI
A RESTful API must adhere to the following principles and characteristics:
- Client-server architecture: separation of client and server logic.
- Stateless: each request from the client to the server must contain all the necessary information; the server does not store state between requests.
- Cacheability: responses should explicitly indicate whether they can be cached to improve performance.
- Uniform interface: use standard HTTP methods (GET, POST, PUT, DELETE, etc.) and clearly define resources via URIs.
- Layered system: architecture can consist of multiple layers, such as proxies, load balancers.
- Code on demand (optional): the server can send executable code to the client (e.g., scripts).
Example: for a "user" resource, the URI might be /users/123, where GET retrieves user data, POST creates a new user, PUT updates, and DELETE deletes.