Course contentsShow
← Software Engineering
Lesson 768 of 1,93324. REST API DesignFree lesson

Success Status Codes: 2xx Range

Selecting appropriate 2xx codes: 200 OK, 201 Created, 202 Accepted, 204 No Content.

Success Status Codes: 2xx Range

You'll learn how to select the right 2xx HTTP status code to accurately communicate successful API operations.

When your REST API successfully processes a request, returning a generic success isn't enough—you need to tell the client what kind of success occurred. The 2xx status code family indicates success, but different codes convey different meanings about what the server did.

The Core 2xx Codes

200 OK is your default success response. Use it when the request succeeded and you're returning data in the response body. For GET requests fetching a user, or PUT requests updating a resource, 200 OK says "here's what you asked for" or "done, here's the updated state."

201 Created specifically signals that a new resource was created. Use this for successful POST requests that add something to your system. It should include a Location header pointing to the new resource's URL.

202 Accepted means "I got your request and will process it later." This is for asynchronous operations where the server queued the work but hasn't completed it yet. Think of it like dropping a package at the post office—they accepted it, but it hasn't reached its destination.

204 No Content indicates success with no response body to send back. Perfect for DELETE operations or updates where the client doesn't need to see the result. It's like a quiet nod: "Done. Nothing more to say."

Choosing Wisely

Match the code to the operation's outcome. Created something? 201. Deleted successfully with nothing to show? 204. Standard retrieval or update? 200. Started a long-running task? 202.

Key Takeaway: Use specific 2xx codes to communicate not just that something succeeded, but how it succeeded—this makes your API clear and predictable for clients.