HTTP Status Codes Interview Questions and Answers

Master HTTP Status Codes with the top 15 interview questions and answers. Learn 2xx, 3xx, 4xx, and 5xx status codes, production use cases, Spring Boot examples, REST API best practices, common mistakes, and interview follow-up questions.

Introduction

HTTP Status Codes are one of the most important aspects of REST API development. Every HTTP request receives a response from the server, and the response contains a status code indicating whether the request was successful, redirected, failed due to a client error, or failed because of a server error.

Interviewers frequently ask candidates not only to explain common status codes like 200, 201, 400, 401, 403, 404, and 500, but also to justify when each should be returned in production applications.

Well-designed REST APIs use meaningful HTTP status codes to improve client communication, simplify debugging, and follow REST standards.

In this guide, you'll learn the 15 most important HTTP Status Code interview questions with production-ready explanations, Spring Boot examples, best practices, common mistakes, and interview scenarios.


What You'll Learn

After completing this guide, you'll be able to:

  • Understand all HTTP Status Code categories.
  • Explain the most commonly used status codes.
  • Return proper status codes in Spring Boot applications.
  • Design production-ready REST APIs.
  • Avoid common API design mistakes.
  • Answer enterprise interview questions confidently.

HTTP Status Code Categories

               HTTP Status Codes

                     Response
                         │
      ┌──────────────────┼──────────────────┐
      ▼                  ▼                  ▼
    2xx                3xx                4xx
 Success          Redirection       Client Errors
                         │
                         ▼
                       5xx
                  Server Errors

1. What are HTTP Status Codes?

Short Answer

HTTP Status Codes are three-digit numbers returned by the server that indicate the outcome of an HTTP request.


Categories

Range Meaning
1xx Informational
2xx Success
3xx Redirection
4xx Client Error
5xx Server Error

Production Example

GET /employees/100

↓

200 OK
GET /employees/999

↓

404 Not Found

Interview Follow-up

Why should REST APIs return meaningful status codes?


2. What is HTTP 200 OK?

Short Answer

200 OK indicates that the request was successfully processed.


Production Example

GET /employees/101

Response

{
  "id":101,
  "name":"John"
}

Status

200 OK

Spring Boot Example

@GetMapping("/{id}")
public ResponseEntity<Employee> getEmployee(@PathVariable Long id){
    return ResponseEntity.ok(service.find(id));
}

Common Uses

  • GET
  • PUT
  • PATCH
  • DELETE (when returning data)

3. What is HTTP 201 Created?

Short Answer

201 Created indicates that a new resource has been successfully created.


Production Example

POST /employees

Server

201 Created

Location:
/employees/101

Spring Boot Example

@PostMapping
public ResponseEntity<Employee> create(
        @RequestBody Employee employee){

    Employee saved = service.save(employee);

    return ResponseEntity
            .status(HttpStatus.CREATED)
            .body(saved);
}

Common Mistakes

Returning 200 OK after creating a resource.


4. What is HTTP 202 Accepted?

Short Answer

202 Accepted means the request has been accepted but processing has not yet completed.


Production Example

POST /payments

Message sent to Kafka

Payment processed asynchronously


Common Uses

  • Kafka
  • RabbitMQ
  • Batch Processing
  • Long-running jobs

Interview Follow-up

When should we return 202 instead of 200?


5. What is HTTP 204 No Content?

Short Answer

204 No Content indicates successful processing without returning a response body.


Production Example

DELETE /employees/101

204 No Content

Spring Boot Example

@DeleteMapping("/{id}")
public ResponseEntity<Void> delete(
        @PathVariable Long id){

    service.delete(id);

    return ResponseEntity.noContent().build();
}

6. What is the Difference Between 301 and 302?

Status Meaning
301 Permanent Redirect
302 Temporary Redirect

Production Example

301

http://company.com

↓

https://company.com

302

Maintenance Page

↓

Temporary Redirect

Common Mistakes

Using 302 when the redirect is permanent.


7. What is HTTP 400 Bad Request?

Short Answer

400 Bad Request indicates that the client sent an invalid request.


Examples

  • Missing required field
  • Invalid JSON
  • Incorrect parameter
  • Validation failure

Spring Boot Example

@PostMapping
public Employee create(
        @Valid
        @RequestBody Employee employee){

    return service.save(employee);
}

Validation failures return 400 Bad Request.


8. What is the Difference Between 401 and 403?

Status Meaning
401 Authentication Required
403 Permission Denied

Production Example

401

Missing JWT Token

403

User Logged In

↓

Not Authorized

Interview Tip

401 = Who are you?

403 = I know you, but you cannot access this resource.


9. What is HTTP 404 Not Found?

Short Answer

404 indicates that the requested resource does not exist.


Production Example

GET /employees/9999

404 Not Found

Common Mistakes

Returning 200 OK with a null object.


10. What is HTTP 409 Conflict?

Short Answer

409 Conflict indicates a conflict with the current state of the resource.


Production Example

POST /users

Email already exists

409 Conflict

Common Uses

  • Duplicate Email
  • Duplicate Username
  • Duplicate Order Number

11. What is HTTP 422 Unprocessable Entity?

Short Answer

422 means the request is syntactically correct but contains invalid business data.


Production Example

Transfer Amount

-1000

Business validation fails

422 Unprocessable Entity

Difference

400

Invalid Request

422

Valid Request

Invalid Business Rule


12. What is HTTP 429 Too Many Requests?

Short Answer

429 indicates the client exceeded the API rate limit.


Production Example

Client

↓

1000 requests/minute

↓

API Gateway

↓

429

Common Uses

  • Public APIs
  • Banking APIs
  • Payment APIs

Response Header

Retry-After: 60

13. What is the Difference Between 500 and 503?

Status Meaning
500 Internal Server Error
503 Service Temporarily Unavailable

Production Example

500

NullPointerException

503

Server Under Maintenance

or

Database Down

Common Mistakes

Returning 500 for every exception.


14. How Should Production APIs Handle Errors?

Example Error Response

{
  "timestamp":"2026-07-21T10:30:00Z",
  "status":404,
  "error":"Not Found",
  "message":"Employee not found",
  "path":"/employees/999"
}

Spring Boot Example

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(EmployeeNotFoundException.class)
    public ResponseEntity<String> handleException(){

        return ResponseEntity
                .status(HttpStatus.NOT_FOUND)
                .body("Employee Not Found");

    }

}

Best Practices

  • Return consistent error responses.
  • Include meaningful error messages.
  • Avoid exposing internal exception details.
  • Log server-side exceptions.

15. Which HTTP Status Codes Should Every Developer Know?

Status Meaning
200 OK
201 Created
202 Accepted
204 No Content
301 Permanent Redirect
302 Temporary Redirect
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found
409 Conflict
422 Unprocessable Entity
429 Too Many Requests
500 Internal Server Error
503 Service Unavailable

HTTP Status Code Summary

Category Range Purpose
Informational 1xx Request Processing
Success 2xx Successful Requests
Redirection 3xx Redirect Client
Client Error 4xx Client Mistakes
Server Error 5xx Server Problems

Interview Tips

When discussing HTTP Status Codes:

  1. Explain the five categories first.
  2. Differentiate 200 vs 201.
  3. Explain 401 vs 403 clearly.
  4. Discuss 400 vs 422.
  5. Explain 500 vs 503 with production examples.
  6. Mention 202 for asynchronous processing.
  7. Use Spring Boot ResponseEntity for returning status codes.
  8. Return meaningful status codes instead of always using 200.

Key Takeaways

  • HTTP Status Codes communicate the result of every client request.
  • 2xx codes indicate successful operations.
  • 3xx codes handle resource redirection.
  • 4xx codes represent client-side errors.
  • 5xx codes represent server-side failures.
  • Use 201 Created after creating resources.
  • Use 204 No Content for successful operations without a response body.
  • Differentiate 401 Unauthorized from 403 Forbidden.
  • Use 409 Conflict for duplicate resources and 422 Unprocessable Entity for business validation failures.
  • Consistent status codes improve API usability, debugging, and maintainability in enterprise applications.