Course contentsShow
← Web Development
Lesson 1488 of 2,98227. REST API Design for FrontendFree lesson

2xx Success Status Codes

Learn the differences between 200 OK, 201 Created, 202 Accepted, and 204 No Content.

2xx Success Status Codes

You'll learn: How to distinguish between the four most common 2xx HTTP success codes and when to use each one.

The Success Family

When a REST API request succeeds, the server responds with a 2xx status code. While they all mean "success," each tells a slightly different story about what kind of success occurred. Think of them as different flavors of "yes" — they all mean affirmative, but with important nuances.

The Four Most Common 2xx Codes

200 OK

The vanilla success response. The request worked, and here's the data you asked for. Use this for successful GET, PUT, or PATCH requests where you're returning content in the response body.

Example: GET /users/123 returns user data → 200 OK

201 Created

Success plus something new exists. Use this for POST requests that create a new resource. Often includes a Location header pointing to the newly created resource.

Example: POST /users creates a new user → 201 Created

202 Accepted

The request was valid and accepted, but processing hasn't finished yet. It's like saying "I got your order, we're working on it." Common for long-running operations or async processing.

Example: POST /reports/generate starts a background job → 202 Accepted

204 No Content

Success, but there's nothing to send back. The action completed, but the response body is intentionally empty. Perfect for DELETE operations or updates where you don't need to return the modified resource.

Example: DELETE /users/123 removes a user → 204 No Content

Choosing the Right Code

Use 200 for standard reads/updates with data, 201 when creating resources, 202 for async operations, and 204 when success means "done, nothing to show."

Key Takeaway: The right 2xx code communicates not just success, but the nature of that success — whether data is returned, something was created, processing is pending, or the operation completed with no content to send back.