ASP.NET Core Web API Interview Question #14
What are HTTP status codes, and why are they important in Web APIs?
Web API & REST Fundamentals, Controllers, HTTP Methods & Status Codes Junior Beginner
Quick Interview Answer
HTTP status codes communicate the high-level outcome of a request using a standardized protocol contract. Clients can use the status code before interpreting the response body.
Detailed Explanation
HTTP status codes communicate the high-level outcome of a request using a standardized protocol contract. Clients can use the status code before interpreting the response body.
A well-designed API uses status codes consistently so success, validation problems, authentication failures, missing resources, conflicts, and server failures are distinguishable without relying on custom text alone.
Code Example
return Ok(product); // 200
return CreatedAtAction(...); // 201
return NoContent(); // 204
return BadRequest(); // 400
return NotFound(); // 404