
Communication between client and server follows the rules defined in the API specification.
REST was invented to standardize these rules.
REST is a style of communication between client and server.
Communication between client and server follows the rules defined in the API specification.
REST was invented to standardize these rules.
REST is a style of communication between client and server.
The client sends requests to the server, which handles processing and data storage.
Separation of concerns allows the client and server to be developed and scaled independently.
Each request contains all the information necessary for the server to process it, such as a JWT authorization token with client information.
The opposite approach is storing client sessions on the server.
The client caches server responses to avoid making repeated requests when the data hasn't changed.
Temporary data storage on the client reduces server load and improves performance.
Resources are represented by consistent URL addresses.
The URL contains the resource name, and the action is determined by the HTTP method.
For example,
GET /cookies/1
The endpoint is named after the resource being operated on, in plural form:
/cookies
— cookie resource
The HTTP method matches the operation performed on the resource:
Method | Example | Description |
---|---|---|
GET | GET /cookies/1 |
Retrieve a cookie |
POST | POST /cookies |
Create a cookie |
PUT | PUT /cookies/1 |
Replace a cookie |
PATCH | PATCH /cookies/1 |
Update a cookie |
DELETE | DELETE /cookies/1 |
Delete a cookie |
The HTTP response code reflects the result of the request:
Code | Meaning |
---|---|
200 OK |
Successful request |
201 Created |
Resource created |
204 No Content |
Success, no content in response |
400 Bad Request |
Bad request |
401 Unauthorized |
Authentication failed |
403 Forbidden |
Access to resource is forbidden |
404 Not Found |
Resource not found |
500 Internal Server Error |
Server error |
Idempotency — repeating the same operation yields the same result.
Idempotent HTTP methods:
Cookie Storage Management
The service allows retrieving, adding, and updating cookies.
Retrieve all cookies.
GET /cookies
200 OK
[
{
"id": 1,
"flavor": "vanilla",
"size": "medium",
"wish": "May your day be sweet!"
},
{
"id": 2,
"flavor": "chocolate",
"size": "small",
"wish": "Success!"
},
{
"id": 3,
"flavor": "cinnamon",
"size": "large",
"wish": "Warmth and comfort!"
}
]
Retrieve a cookie by identifier.
GET /cookies/{id}
200 OK
{
"id": 1,
"flavor": "vanilla",
"size": "medium",
"wish": "May your day be sweet!"
}
Add a cookie.
POST /cookies
Request in JSON format:
Field | Type | Required | Restrictions |
---|---|---|---|
flavor | string | + | chocolate, vanilla, cinnamon |
size | string | + | small, medium, large |
wish | string | + | 1 to 255 characters |
201 Created
{
"id": 1,
"flavor": "vanilla",
"size": "medium",
"wish": "May your day be sweet!"
}
If the storage is full —
507 Insufficient Storage
with the message “Storage is full”.
Update a cookie.
PUT /cookies/{id}
Request in JSON format:
Field | Type | Required | Restrictions |
---|---|---|---|
flavor | string | + | chocolate, vanilla, cinnamon |
size | string | + | small, medium, large |
200 OK
{
"id": 1,
"flavor": "vanilla",
"size": "medium",
"wish": "May your day be sweet!"
}
Partially update a cookie.
PATCH /cookies/{id}
Request in JSON format:
Field | Type | Required | Restrictions |
---|---|---|---|
flavor | string | - | chocolate, vanilla, cinnamon |
size | string | - | small, medium, large |
204 No Content
Data format: application/json
All API requests must be sent with a JWT token in the Authorization header.
Уровень повышен!