· documentation · 3 min read
By Amanda SHTTP Verbs - CRUD Operations In JSON Rest APIs
Discover the essential roles of HTTP verbs in JSON REST APIs. This guide offers a concise breakdown of GET, POST, PUT, PATCH, and DELETE methods, enabling you to design efficient and effective API interactions. Gain the expertise needed to optimize data retrieval, manipulation, and deletion within your JSON-based RESTful services.
HTTP Verbs in REST APIs: GET, POST, PUT, PATCH, DELETE
HTTP verbs define how clients interact with resources in a REST API. Each verb maps to a specific type of operation: fetching data, creating records, updating them, or deleting them. Used correctly, they make APIs predictable and easier to work with.
Common HTTP Verbs
Here are some of the most common HTTP verbs and their significance in REST APIs:
GET: It should not modify data or trigger side effects. Browsers use
GETrequests constantly when loading pages, images, or API responses.POST:
POSTcreates a new resource. The client sends data to the server, and the server processes it to create something new. Unlike GET or PUT, POST requests are generally not idempotent. Sending the same POST request multiple times may create multiple records.PUT:
PUTreplaces an existing resource with the payload sent by the client. If the resource does not exist, some APIs create it.PUTis idempotent by nature. Repeating the same request should leave the resource in the same state.PATCH: PATCH updates part of a resource instead of replacing the whole object. PATCH reduces payload size and avoids sending unchanged data.
DELETE:
DELETEdoes what its name suggests—it removes a resource. It’s like tearing a page out of a book; the resource is gone once the request is processed.DELETEis usually idempotent. Deleting the same resource multiple times should not produce different results.
Comparing HTTP Verbs for Idempotence
| HTTP Verb | Idempotence? | Side Effects? | Has Payload? | Usage Limits and Notes | Example |
|---|---|---|---|---|---|
| GET | Yes | No side effects | No | Safe, used for retrieving data. No request body is sent. | Fetching a user’s profile: GET /users/123 |
| POST | No | May create resources | Yes | Typically used for creating new resources. | Creating a new post: POST /posts |
| PUT | Yes | Replaces resource | Yes | Used for full updates or resource creation if the resource does not exist. | Updating a user’s information: PUT /users/123 |
| PATCH | No | Modifies resource | Yes | Used for partial updates. | Modifying a specific comment: PATCH /comments/456 |
| DELETE | Yes | Removes resource | No | Used for resource removal. No request body is sent. | Deleting a post: DELETE /posts/789 |
Role In Rest APIs
These HTTP verbs are essential in REST APIs for several reasons:
- Uniform Interface: REST APIs use a uniform and consistent set of HTTP verbs, making it easy for developers to understand and work with various APIs. This uniformity simplifies the design and use of APIs.
- Statelessness: HTTP is a stateless protocol, meaning each request from a client to a server must contain all the information needed to understand and process the request. HTTP verbs help maintain this statelessness by clearly specifying the action to be taken.
- Resource Management: The verbs define how resources are manipulated. This aligns well with the RESTful principle of treating everything as a resource, making it intuitive for developers to work with data.
- Idempotence: Some verbs (GET, PUT, DELETE) are designed to be idempotent, meaning that performing the same action multiple times has the same result as doing it once. This property is essential for predictable and safe interactions.
- Security: Properly using HTTP verbs can enhance the security of your API. For example, sensitive operations should not use GET requests, as GET requests can be cached and logged, potentially exposing sensitive data.
Final Note
A well-designed REST API works smoothly with the web itself:
- caches behave correctly
- retries stay safe
- clients remain predictable
- tooling interoperates cleanly
That reliability comes from
HTTP methods are not arbitrary conventions. Their behavior is formally defined in HTTP RFCs, and REST APIs build on top of those semantics. When APIs misuse verbs, clients, proxies, caches, SDKs, browsers, and retry systems start behaving unpredictably.