Skip to main content

HTTP Basics

HTTP Basics

HTTP is a stateless, request–response protocol.

  • Client sends a request → server sends a response
  • Each request is independent

Memory line: HTTP = stateless request → response


HTTP Server & Kestrel

HTTP server processes requests and returns responses.

Examples: IIS, Nginx, Apache, Kestrel

Kestrel

  • Built into ASP.NET Core
  • Fast, cross-platform
  • Runs the app and handles requests

Memory line: Kestrel is the web server that runs ASP.NET Core.


Request → Response Flow (ASP.NET Core)

Client → Kestrel → Middleware → App → Middleware → Kestrel → Client

Memory line: Every request goes through middleware.


HTTP Request (Client → Server)

4 parts (in order):

  1. Start line (Method + Path + Version)
  2. Headers
  3. Empty line
  4. Body (optional)

Common methods:

  • GET → read
  • POST → create
  • PUT → update
  • DELETE → delete

Memory line: Request = method + path + headers + body.


Query Strings

Data in URL: ?key=value&key2=value2

  • Used mainly with GET

Memory line: Query strings = small data in URL.


HTTP Response (Server → Client)

3 parts:

  1. Status line (200, 404, etc.)
  2. Headers
  3. Body (optional)

Common headers:

  • Content-Type
  • Content-Length
  • Cache-Control
  • Set-Cookie

Memory line: Response = status + headers + body.


Status Codes (Only Remember These)

  • 200 OK
  • 201 Created
  • 204 No Content
  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 500 Server Error

Memory trick:

  • 2xx = success
  • 4xx = client error
  • 5xx = server error

GET vs POST (Interview Favorite)

GETPOST
Read dataSend data
Data in URLData in body
CacheableNot cacheable
IdempotentNot idempotent

One-liner: GET reads, POST changes.


9️⃣ ASP.NET Core Request Access

HttpContext.Request

  • Method
  • Path
  • Query
  • Headers
  • Body

HttpContext.Response

  • StatusCode
  • Headers
  • WriteAsync()

Memory line: Request in, Response out — both via HttpContext.


Tools

  • Browser DevTools → inspect requests/responses
  • Postman → test APIs manually

Memory line: Postman tests APIs without a browser.