What is a REST API, and what makes an API RESTful?
EasyConceptAPIs & Communication
Answer
REST (Representational State Transfer) is an architectural style in which clients manipulate resources, identified by URLs, through standard HTTP methods. A RESTful API is stateless, uses a uniform interface, and exchanges representations such as JSON.
- Methods:
GETreads,POSTcreates,PUTreplaces,PATCHpartially updates andDELETEremoves.GET,PUTandDELETEare idempotent;POSTis not. - Resource naming: use nouns and hierarchy, such as
GET /users/42/orders, not verbs like/getOrders. - Status codes: 200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, 429 Too Many Requests, 500 Internal Server Error.
- Statelessness: each request carries everything needed, including authentication, which simplifies horizontal scaling and caching.
More in APIs & Communication
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | What is a REST API, and what makes an API RESTful? | Concept | Easy | Read the answer to What is a REST API, and what makes an API RESTful? | |||
| 2 | When would you choose REST, GraphQL or gRPC? | Concept | Medium | Read the answer to When would you choose REST, GraphQL or gRPC? | |||
| 3 | What is idempotency, and how do you make a POST request safe to retry? | Concept | Medium | Read the answer to What is idempotency, and how do you make a POST request safe to retry? | |||
| 4 | How do short polling, long polling, WebSockets and Server-Sent Events differ? | Concept | Medium | Read the answer to How do short polling, long polling, WebSockets and Server-Sent Events differ? |