Course contentsShow
← Software Engineering
Lesson 773 of 1,93324. REST API DesignFree lesson

Matching Verbs to Status Codes

Best practices for pairing HTTP methods with appropriate response status codes for common operations.

Matching Verbs to Status Codes

What you'll learn: How to pair HTTP methods with the correct status codes to create predictable, well-designed REST APIs.

Understanding the Relationship

Each HTTP verb implies a specific operation, and your API should respond with status codes that accurately reflect what happened. Think of it like a conversation: the client asks something (verb), and the server replies with a specific response (status code) that makes sense for that type of request.

Common Verb-Status Pairings

GET requests typically return:

  • 200 OK when the resource exists
  • 404 Not Found when it doesn't
  • 304 Not Modified for cached responses

POST requests (creating resources) should return:

  • 201 Created on successful creation
  • 400 Bad Request for invalid data
  • 409 Conflict if the resource already exists

PUT requests (full updates) commonly return:

  • 200 OK when updating and returning the resource
  • 204 No Content when updating without a response body
  • 404 Not Found if the resource doesn't exist

PATCH requests (partial updates) use:

  • 200 OK with the updated resource
  • 422 Unprocessable Entity for validation errors

DELETE requests typically return:

  • 204 No Content on successful deletion
  • 404 Not Found if already deleted or never existed

Why This Matters

Consistent verb-status pairings make your API intuitive. Developers using your API shouldn't receive 200 OK after a POST that failed, or 201 Created from a GET request. Each pairing tells a clear story about what happened, enabling proper error handling and creating a professional developer experience.

Key Takeaway: Match HTTP verbs with semantically appropriate status codes—successful creation returns 201, successful deletion returns 204, missing resources return 404—to build APIs that communicate clearly and behave predictably.