Loading...
Loading...
By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.
👋 Hi! I'm Dastan, author of Hack Frontend. Always open to professional networking => connect with me on LinkedIn.
REST (Representational State Transfer) is architectural style for creating distributed applications. REST uses standard HTTP methods and principles for interaction between client and server. In RESTful API requests are executed using standard HTTP methods such as GET, POST, PUT and DELETE to work with resources.
REST principles are described through several key constraints that help create flexible, scalable and easy-to-maintain web services. Let's examine main REST principles:
REST uses client-server model, where client and server are separated and independent. Client sends requests to server, which processes them and sends responses. This separation allows server to be independent from client, and also simplifies development, updates and support.
RESTful API is stateless, meaning each request from client to server must contain all information necessary to process request. Server doesn't store information about previous requests, and each request is considered independently.
Server responses can be cacheable if necessary for performance improvement. Caching allows storing frequently requested data in memory or on disk to avoid repeated server requests.
REST has uniform interface that standardizes interaction between client and server. This simplifies API creation and use, as client always interacts with API the same way, regardless of server's internal implementation.
Uniform interface includes:
RESTful API can be layered, meaning server can be divided into several layers, each performing its task. For example, one layer may handle request processing, another — authentication, third — database processing, etc. Client can interact only with outer layer, not knowing about other layers.
This principle is not always used in REST, but it allows server to send executable code, such as JavaScript, to client for execution. This allows server to change client behavior if necessary.
In REST each object or data transmitted between client and server is a resource. Resources are identified using unique URLs. Client interacts with these resources using standard HTTP methods (GET, POST, PUT, DELETE).
Imagine we have service for managing users. Some HTTP requests for this API may look like this:
GET /users — Get list of all users.GET /users/{id} — Get user information by ID.POST /users — Create new user.PUT /users/{id} — Update user information by ID.DELETE /users/{id} — Delete user by ID.