HTTP Methods & Status Codes

The 4 verbs + 5 numbers that run every API on the internet.

The Rule: If you understand GET, POST, 200, 404 - you can use 80% of all APIs in the world.

1. The Zomato Order Flow = All 4 HTTP Methods

Think of an API like talking to a waiter. You don't just say "pizza". You specify the action:

Your ActionHTTP MethodZomato Example
Ask for menuGETGET /api/restaurants - Get all restaurants
Place orderPOSTPOST /api/orders - Create new order
Change addressPUTPUT /api/orders/123 - Update full order
Cancel orderDELETEDELETE /api/orders/123 - Delete order

CRUD = Create POST, Read GET, Update PUT, Delete DELETE. That's it.

2. Status Codes = The Server's Reply

After you send a request, server replies with a 3-digit code. Learn these 5:

200 OK

"Got it. Here's your data."
GET worked.

201 Created

"I made your order."
POST worked.

400 Bad Request

"Your order is missing address."
You sent bad data.

404 Not Found

"Restaurant ID 999 doesn't exist."
You asked for wrong thing.

500 Server Error

"Our kitchen caught fire."
Our code crashed.

3. Code It: Zomato Order API

Add to your ZomatoController from last lesson:

// GET: api/zomato/restaurants/1
[HttpGet("restaurants/{id}")]
public ActionResult GetRestaurant(int id) {
    var r = restaurants.Find(x => x.Id == id);
    return r == null? NotFound() : Ok(r); // 404 or 200
}

// POST: api/zomato/orders
[HttpPost("orders")]
public ActionResult CreateOrder([FromBody] Order order) {
    order.Id = 123; // pretend we saved to DB
    return CreatedAtAction(nameof(GetOrder), new { id = order.Id }, order); // 201
}

[HttpGet("orders/{id}")]
public ActionResult GetOrder(int id) {... }

Test in Swagger: POST an order โ†’ get 201. GET wrong ID โ†’ get 404. You're speaking HTTP now.

Career-Killer Mistake: Using POST for everything.
POST /api/GetUser and POST /api/DeleteUser is junior code.
Why you get fired: Breaks caching, breaks browser history, confuses every tool. GET = read, POST = create. Follow the spec.

Quick Check ๐Ÿง 

You now speak API. Next lesson: Model Binding & Validation - How data gets from HTTP request into your C# parameters, and why 400 happens. Continue โ†’

Comments on HTTP Methods (0)

No comments yet. Be the first to share your thoughts!