REST, or Representational State Transfer, focuses on the representation of entities within a system. It operates on a client-server architecture where a client sends a request, and the server responds, typically in JSON format. In this context, every element is treated as a resource. For example, in a library management system, a student is considered a resource.
REST provides flexibility in client-server communication by allowing clients to request data in multiple formats, such as CSV, JSON, or XML. While REST specifies how clients should request data from servers and how servers should respond, it does not dictate how data should be stored in databases. This means that developers have the freedom to choose their preferred storage methods without being restricted by REST principles.
REST utilizes HTTP methods - GET
, POST
, PUT
, and DELETE
- to interact with resources. The URL path, such as /students/1
, specifies the resource, while the HTTP method signifies the intended action, for example, DELETE
. This approach fosters a clear and consistent design for APIs.
While REST provides several advantages, it comes with notable challenges. One significant issue is the difficulty in consuming REST APIs, as converting JSON responses into native objects can be cumbersome. Additionally, the payloads in HTTP, generally formatted in JSON, tend to be large and may result in slow performance for low-latency applications.