Why Some RESTful APIs Stick to GET/POST and Always Return 200
The article examines common misconceptions in RESTful API design, explaining why developers often limit interfaces to GET and POST, why some APIs return only HTTP 200 status codes, and how to decide the proper use of other methods and status codes for empty results.
Introduction
RESTful API design is widely used in modern web applications, especially in front‑back separation architectures. Many developers encounter three recurring questions: why an API only defines GET and POST, why the HTTP status code is always 200 regardless of success, and how to handle empty query results.
Why Only GET and POST?
HTTP defines several request methods, each with a specific purpose:
GET : Retrieve a resource without side effects.
POST : Submit data to create or modify a resource.
PUT : Replace the entire target resource.
PATCH : Apply partial updates to a resource.
DELETE : Remove a resource.
Because GET and POST are the most frequently used, some teams simplify their APIs by exposing only these two methods. This reduces the need to think about method semantics, but it also sacrifices the expressive power of HTTP.
// Example of a concise request
GET https://tinywan.com/users
DELETE https://tinywan.com/users/69When only GET and POST are used, developers often encode the intended action in the URL, e.g., POST https://tinywan.com/delete/user/1. While functional, such URLs become verbose and obscure the true intent of the operation.
Proper RESTful Example
// Standard RESTful endpoints
GET https://tinywan.com/users // list users
GET https://tinywan.com/users/1 // get user 1
POST https://tinywan.com/users // create user
PUT https://tinywan.com/users/1 // replace user 1
PATCH https://tinywan.com/users/69 // partially update user 69
DELETE https://tinywan.com/users/1 // delete user 1Non‑RESTful Example (GET/POST Only)
// All actions use POST except simple reads
GET https://tinywan.com/users
GET https://tinywan.com/users/1
POST https://tinywan.com/users // create
POST https://tinywan.com/put/users/1 // replace (mis‑named)
POST https://tinywan.com/patch/user/69 // partial update (mis‑named)
POST https://tinywan.com/delete/user/1 // delete (mis‑named)Using POST for every mutating operation forces developers to add descriptive path segments, leading to longer, less elegant URLs.
Why Some APIs Always Return HTTP 200
Common HTTP status codes include:
200 OK – request succeeded.
201 Created – a new resource was created.
400 Bad Request – client‑side validation error.
401 Unauthorized – authentication required.
403 Forbidden – request understood but refused.
404 Not Found – resource does not exist.
429 Too Many Requests – rate limit exceeded.
500 Internal Server Error – server‑side failure.
Some teams return 200 for every response and embed an application‑specific error code in the JSON body:
// Always 200, custom error payload
{
"code": 1024,
"message": "Password incorrect"
}This approach works for tiny demos but becomes problematic as the system grows. Front‑end developers must maintain large if/else or switch blocks to map custom codes to UI actions, and any change in the error catalog forces widespread code updates.
By leveraging proper HTTP status codes, the front end can first branch on the status (e.g., 4xx vs 5xx) and then handle specific error codes only when needed, dramatically simplifying error handling and improving communication between front‑ and back‑end teams.
When an Empty Result Should Return 200 vs 404
If a query yields no data, the appropriate status depends on business semantics:
200 OK – when an empty result is a valid outcome (e.g., “no users logged in for the past month”).
404 Not Found – when the requested resource must exist (e.g., attempting to update a non‑existent user).
Choosing the correct status helps front‑end code distinguish between “nothing to show” and “invalid request,” leading to more robust applications.
Conclusion
While it is technically possible to ignore HTTP method distinctions and always return 200, doing so sacrifices the clarity, semantics, and tooling benefits that RESTful design provides. Proper use of HTTP verbs and status codes improves API readability, reduces client‑side complexity, and aligns with industry standards.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
