Skip to content Skip to footer

Complete HTTP Status Codes for .NET Core APIs

1xx – Informational

CodeNameWhen to Use
100ContinueClient should continue with request (rare in APIs)
101Switching ProtocolsUpgrading to WebSocket
102ProcessingLong-running operation in progress (WebDAV)
103Early HintsSend headers before final response

2xx – Success

CodeNameWhen to Use
200OKStandard success – GET, PUT, PATCH
201CreatedPOST created new resource – include Location header
202AcceptedRequest accepted, processing async (queued jobs)
204No ContentDELETE success, or PUT/PATCH with no response body
205Reset ContentTell client to reset form/view
206Partial ContentReturning part of resource (Range requests)
207Multi-StatusMultiple operation results (WebDAV)
208Already ReportedResource already reported (WebDAV)
226IM UsedDelta encoding applied

3xx – Redirection

CodeNameWhen to Use
300Multiple ChoicesMultiple representations available
301Moved PermanentlyResource moved forever – update bookmarks
302FoundTemporary redirect – use original URI next time
303See OtherRedirect to GET after POST
304Not ModifiedCached version is still valid (ETag match)
307Temporary RedirectLike 302 but preserve HTTP method
308Permanent RedirectLike 301 but preserve HTTP method

4xx – Client Errors

CodeNameWhen to Use
400Bad RequestInvalid JSON, malformed request, validation failed
401UnauthorizedMissing or invalid authentication token
402Payment RequiredPayment needed (rarely used)
403ForbiddenAuthenticated but not authorized (no permission)
404Not FoundResource doesn’t exist
405Method Not AllowedWrong HTTP verb (POST to GET-only endpoint)
406Not AcceptableCan’t produce requested Accept format
407Proxy Authentication RequiredProxy needs authentication
408Request TimeoutClient took too long to send request
409ConflictResource conflict (duplicate, version mismatch)
410GoneResource permanently deleted
411Length RequiredContent-Length header missing
412Precondition FailedIf-Match or If-None-Match failed
413Payload Too LargeRequest body exceeds limit
414URI Too LongURL exceeds maximum length
415Unsupported Media TypeWrong Content-Type (sent XML, expected JSON)
416Range Not SatisfiableInvalid Range header
417Expectation FailedExpect header can’t be met
418I’m a TeapotEaster egg (don’t use in production)
421Misdirected RequestRequest sent to wrong server
422Unprocessable EntityValid JSON but business logic validation failed
423LockedResource is locked (WebDAV)
424Failed DependencyRequest failed due to previous failure
425Too EarlyServer unwilling to risk replay attack
426Upgrade RequiredClient must upgrade protocol
428Precondition RequiredRequest must be conditional
429Too Many RequestsRate limit exceeded
431Request Header Fields Too LargeHeaders too large
451Unavailable For Legal ReasonsCensored/blocked by law

5xx – Server Errors

CodeNameWhen to Use
500Internal Server ErrorUnhandled exception, generic server error
501Not ImplementedFeature not implemented
502Bad GatewayInvalid response from upstream server
503Service UnavailableServer overloaded or maintenance mode
504Gateway TimeoutUpstream server timeout
505HTTP Version Not SupportedHTTP version not supported
506Variant Also NegotiatesContent negotiation error
507Insufficient StorageServer out of storage (WebDAV)
508Loop DetectedInfinite loop in request (WebDAV)
510Not ExtendedFurther extensions needed
511Network Authentication RequiredNetwork access requires authentication

.NET Core Implementation Examples

// Most common patterns in .NET Core APIs

// Success responses
return Ok(data);                          // 200
return Created($"/api/users/{id}", user); // 201
return NoContent();                       // 204

// Client errors
return BadRequest("Invalid input");       // 400
return Unauthorized();                    // 401
return Forbid();                          // 403
return NotFound();                        // 404
return Conflict("User already exists");   // 409
return UnprocessableEntity(errors);       // 422
return StatusCode(429, "Rate limited");   // 429

// Server errors
return StatusCode(500, "Internal error"); // 500
return StatusCode(503, "Unavailable");    // 503

Quick Decision Guide

Creating resource? → 201 Created
Deleting resource? → 204 No Content
Updating resource? → 200 OK or 204 No Content
Invalid JSON/format? → 400 Bad Request
Business validation failed? → 422 Unprocessable Entity
No auth token? → 401 Unauthorized
Valid token, no permission? → 403 Forbidden
Resource doesn’t exist? → 404 Not Found
Duplicate resource? → 409 Conflict
Unhandled exception? → 500 Internal Server Error
External API failed? → 502 Bad Gateway
Too many requests? → 429 Too Many Requests

Common Mistakes

401 vs 403: Use 401 for missing/invalid credentials, 403 for insufficient permissions
400 vs 422: Use 400 for malformed requests, 422 for valid format but invalid business logic
200 vs 204: Use 204 when there’s no response body (especially DELETE)
404 vs 410: Use 410 only if resource was intentionally removed and won’t return
502 vs 504: Use 502 for bad response from upstream, 504 for timeout

Leave a Comment