Sobes.tech
Senior

What is RESTful? What are the criteria for REST?

sobes.tech AI

Answer from AI

RESTful is an architectural style for web services based on the principles of REST (Representational State Transfer).

REST criteria:

  1. Client-server architecture. Clients and servers are separated, which simplifies development and scaling.
  2. Statelessness. Each request from the client to the server must contain all the information needed; the server does not store state between requests.
  3. Caching. Responses should explicitly indicate whether they can be cached to improve performance.
  4. Uniform interface. Use of standard HTTP methods (GET, POST, PUT, DELETE) and clear resource identification via URIs.
  5. Layered system. The architecture can consist of multiple layers, such as proxies and load balancers, which do not affect client-server interaction.
  6. Code on demand (optional). The server can transfer executable code to the client (e.g., scripts).

Example of a RESTful API:

  • GET /users — get a list of users
  • POST /users — create a new user
  • GET /users/123 — get user with id=123
  • PUT /users/123 — update user data
  • DELETE /users/123 — delete user

RESTful services are simple, scalable, and use standard web technologies.