HTTP status codes: success (2xx)
This course covers the 2xx family of HTTP status codes, which signal that a request succeeded. It starts with how status codes work, the five families and the status line. It then explains 200 OK, 201 Created with the Location header, 204 No Content, 202 Accepted for background work and 206 Partial Content for range requests. A decision tree maps HTTP methods to the right code. The last lesson shows how Rails sends and tests these codes with render, head, redirect_to and respond_to.
What you'll learn
- ✓How status codes, the five families and the status line work
- ✓When to return 200 OK and when to avoid it
- ✓How 201 Created and the Location header describe a new resource
- ✓The rules of 204 No Content and its role in CORS preflight
- ✓How 202 Accepted and 206 Partial Content handle async jobs and range requests
- ✓How Rails sets and tests success codes in controllers
What are HTTP status codes?
Every time a client (browser, mobile app, API consumer) sends an HTTP request, the server sends back a response. The very first thing in that response is a three-digit number called the status code.
Read the full lesson free →Curriculum
7 lessonsWhat are HTTP status codes?
Explains the status line, the five status code families and why browsers, crawlers and infrastructure rely on them.
200 OK: the standard success
Covers when servers return 200 OK per method, response formats, caching behavior and common mistakes with 200.
201 Created: a resource was born
Explains 201 Created, the Location header, server-generated fields in the body and when PUT returns 201.
204 No Content: success, nothing to say
Describes 204 No Content for deletes and actions, its no-body rule, browser behavior and CORS preflight.
Other 2xx codes: 202 and 206
Covers 202 Accepted with the polling pattern and 206 Partial Content with Range and Content-Range headers.
Choosing the right success code
Gives a decision tree, method-to-code mappings, real-world scenarios and common mistakes when picking a success code.
Success codes in Rails
Shows how Rails sends success codes with render, head, redirect_to, respond_to and Active Job, and how to test them.