A REST API (Representational State Transfer Application Programming Interface) is a set of rules and standards that software programs can use to communicate with each other over the internet. It’s a popular architectural style for designing networked applications, often used for web services.
An operation is idempotent if making the same request multiple times produces the same result as making it just once. In other words, repeating the operation doesn’t change the outcome after the initial successful execution. Only the state of the server is considered, not the response code.
https://learn.microsoft.com/en-us/azure/architecture/best-practices/api-design
https://www.restapitutorial.com/httpstatuscodes.html
Method | Example | Status Code |
---|---|---|
GET | /users/:id | 200 OK |
POST | /users | 201 Created |
PUT | /task/:name | New: 201 Create; Exists: 200 OK or 204 No Content |
PATCH | /user/:id | 2xx |
Examples
New User
POST /users
{
name: “Amar”
}
201 Created
Not idempotent - as new users created every time
Get User
GET /users/:id
Idempotent
Upsert User
PUT /task/:name
201 Create if new,
200 OK or 204 NO CONTENT if exists
Idempotent
Complete representation of a resource
Modify some fields
PATCH /user/:id
{
name: “New name”
}
Idempotent
HEAD, OPTIONS, GET, PUT, DELETE
https://developer.mozilla.org/en-US/docs/Glossary/Idempotent