REST API (Representational State Transfer Application Programming Interface) is a web service architecture. This architecture encompasses a set of standards that represent resources and define operations performed on these resources. REST typically communicates over the HTTP protocol but can also be used with other protocols.
Resource Representation: Each resource is represented by a URI (Uniform Resource Identifier). These resources are typically data represented in JSON
or XML
format.
Lightweight Communication: REST communicates using existing communication protocols like HTTP, contributing to the overall lightweight nature of the application.
Statelessness: Each request contains its context, and the server does not store this context. Every request must carry all the relevant information with it.
Layered Architecture: REST follows a layered architecture, making the application modular and more sustainable.
Interconnected Systems: RESTful services can interact with each other, enabling access to a resource in one system through other interconnected systems.
REST APIs often support CRUD (Create, Read, Update, Delete) operations. For example, in a book store application, CRUD operations could be as follows:
Create: Use a POST
request to add a new book.
Read: Use a GET
request to view specific book details.
Update: Use a PUT
or PATCH
request to update book information.
Delete: Use a DELETE
request to remove a book.
Commonly Used Status Codes
Code | Meaning | Description |
200 | OK | The request was successfully processed. |
201 | Created | The resource was successfully created. |
204 | No Content | The request was successful, but there is no content to return. |
400 | Bad Request | The request could not be understood or processed by the server. |
401 | Unauthorized | Authentication failed or user lacks necessary permissions. |
403 | Forbidden | The request was valid, but the server refuses to respond. |
404 | Not Found | The requested resource could not be found. |
405 | Method Not Allowed | The request method is not supported for the requested resource. |
409 | Conflict | The request could not be completed due to a conflict with the current state of the target resource. |
500 | Internal Server Error | An unexpected error occurred on the server. |
503 | Service Unavailable | The server is currently unable to handle the request, usually due to temporary overloading or maintenance of the server. |
REST APIs can be utilized for a wide range of applications and were developed to standardize the interaction of web-based services.