Characteristics that make an API RESTful
What makes an API RESTful ?
An API (Application Programming Interface) is RESTful when it adheres to the principles of REST (Representational State Transfer). Representational State Transfer (REST) is an architectural style that is commonly used for web-based APIs alongside HTTP as the transport protocol.
🔸 Stateless: The server shouldn’t need to store any information about a user between requests. Everything that the server needs to execute a task should be sent in the request.
🔸 Separation of concerns: The client and server should function independently of each other. The client and server are separate entities that interact through a well-defined interface. The client is responsible for the user interface and user experience, while the server is responsible for the business logic and data storage.
🔸 Cacheable: Responses can be cached on the client to boost performance. Responses from the server should be explicitly labeled as cacheable or non-cacheable. This allows clients to cache responses and improve performance by reducing the need for redundant requests to the server.
🔸 Consistent interface: The interface between the client and server should be uniform and standardized. This typically involves using standard HTTP methods (GET, POST, PUT, DELETE) and resource identifiers (URLs) to perform operations on resources.
🔸 Resource-based: RESTful APIs have an emphasis on resources rather than methods or functions. A resource can be an object, entity, or data within a system. Resources are uniquely identified using a Uniform Resource Identifier (URI).
🔸 Standard media types: Responses are usually sent as JSON, XML, or plain text. Clients can request a preferred media type.
🔸 Code on Demand (Optional): Servers can optionally provide executable code (such as JavaScript) to be executed within the client’s runtime environment. This allows for dynamic behavior and extensibility of the client.
Happy Reading!