Sobes.tech
Senior

What are the principles of REST API? When is it considered RESTful?

sobes.tech AI

Answer from AI

REST (Representational State Transfer) is an architectural style for creating web services. The main principles of REST API:

  • Client-server architecture: the client and server are separated, which simplifies development and scaling.
  • Stateless: each request from the client to the server must contain all the necessary information; the server does not store state between requests.
  • Caching: responses should explicitly indicate whether they can be cached to improve performance.
  • Uniform interface: standardized methods (GET, POST, PUT, DELETE, etc.), uniform URI formats, use of standard response codes.
  • Layered system: architecture can be multi-layered; the client should not need to know which layer it is interacting with.
  • Code on demand (optional): the server can transfer executable code to the client.

RESTful API is an API that strictly follows these principles. For example, resources are represented as URLs, operations on them correspond to HTTP methods, responses have correct status codes, and contain hypermedia links (HATEOAS) for API navigation.