Skip to content

2xx Success Codes — Standard Response Status Codes

DodaTech Updated 2026-06-28 1 min read

In this tutorial, you will learn about 2xx success codes. We cover key concepts, practical examples, and best practices to help you master this topic.

2xx status codes indicate successful API requests. The specific code signals what happened: resource retrieved, created, accepted for processing, or deleted with no body.

Code Reference

200 OK: GET requests returning resources, PUT/PATCH updates returning the updated resource. 201 Created: POST requests that create a new resource. Include Location header with resource URL. 202 Accepted: Request accepted for asynchronous processing. Return polling URL. 204 No Content: DELETE success or PUT/PATCH when no body returned.

Examples

// 201 Created with Location header
app.post("/api/users", (req, res) => {
  const user = createUser(req.body);
  res.status(201)
    .location(`/api/users/${user.id}`)
    .json(user);
});

// 202 Accepted for async operation
app.post("/api/reports", (req, res) => {
  const reportId = startReportGeneration(req.body);
  res.status(202)
    .json({
      status: "processing",
      reportId,
      pollingUrl: `/api/reports/${reportId}/status`
    });
});

// 204 No Content for delete
app.delete("/api/users/:id", (req, res) => {
  deleteUser(req.params.id);
  res.status(204).send();
});

Common Mistakes

  1. Using 200 for POST create — POST should return 201.
  2. Returning body with 204 — 204 must have no body.
  3. No Location header with 201 — Clients need to know the resource URL.

Practice Questions

  1. When should you use 201?
  2. What does 202 Accepted mean?
  3. Why does 204 have no body?

What's Next

In the next lesson, you will learn 3xx redirection codes.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro