Skip to main content

HTTP Methods & Status Codes

When you send a request to a REST API, you are essentially sending a message. To make sure the server understands you, you must use specific Methods. Once the server processes your request, it replies with a Status Code.

HTTP Methods (The "Verbs")

Every request starts with a method that defines the intent of the action.

Purpose: Retrieve Data

Used when you want to "fetch" information. It is Read-Only.

  • Analogy: Browsing a menu at a cafe.
  • Example: GET /users (Get all users).

HTTP Status Codes (The Feedback)

After you send a request, the server sends back a 3-digit number. This tells the client exactly what happened.

RangeCategory"Desi" MeaningTypical Examples
2xxSuccess"Sab sahi hai!" (All Good)200 OK, 201 Created
3xxRedirection"Rasta badal lo." (Go elsewhere)301 Moved Permanently
4xxClient Error"Tumhari galti hai." (Your fault)400 Bad Request, 404 Not Found
5xxServer Error"Meri galti hai." (My fault)500 Internal Server Error

Understanding the "Big Three" Codes

  1. 200 OK: The request was successful, and here is your data!
  2. 404 Not Found: The URL you requested doesn't exist. (The "classic" internet error).
  3. 500 Internal Server Error: Your code crashed on the server. The client did nothing wrong, but the backend failed.

Summary Checklist

  • I know that GET is for reading and POST is for creating.
  • I understand the difference between PUT (Full update) and PATCH (Partial).
  • I can identify that 4xx codes mean the issue is on the user's side.
  • I know that 201 is the standard code for a successful "Create" action.
Common Beginner Mistake

Never use GET to send sensitive data like passwords! Data in a GET request is visible in the URL. Always use POST with a "Body" for secure information.