Redirection Status Codes: 3xx Range
What you'll learn: How REST APIs use 3xx status codes to tell clients that a resource has moved or can be reused from cache.
What Are 3xx Redirection Codes?
When a REST API responds with a status code in the 3xx range, it's saying: "The resource you want exists, but you need to look somewhere else—or you already have what you need." These codes guide clients to the correct location or optimize performance by avoiding unnecessary data transfers.
Think of it like asking for directions: instead of getting the answer directly, you're told "it's moved to the next building" or "you already wrote down the answer in your notebook."
The Key 3xx Status Codes
301 Moved Permanently
This tells the client: "The resource has permanently moved to a new URL—update your bookmarks." The server includes a Location header pointing to the new address. Clients and search engines should use the new URL going forward.
Use case: You've restructured your API and /api/v1/users is now /api/v2/users forever.
302 Found
This means: "The resource is temporarily at a different URL right now." Unlike 301, this is temporary—the original URL might work again later. The client should keep using the original URL for future requests.
Use case: Temporary maintenance redirect or A/B testing different endpoints.
304 Not Modified
This optimizes performance: "The resource hasn't changed since you last fetched it—use your cached copy." The server sends no body, saving bandwidth. This works with conditional request headers like If-Modified-Since.
Use case: A client requests user data but already has the latest version cached.
Why This Matters
Redirection codes maintain REST's statelessness while enabling resource mobility and caching. They tell clients how to handle a response, not just whether it succeeded.
Key Takeaway: 3xx codes handle resource location changes (301, 302) and cache validation (304), making REST APIs flexible and efficient without breaking the client-server contract.