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):
- Start line (Method + Path + Version)
- Headers
- Empty line
- 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:
- Status line (200, 404, etc.)
- Headers
- Body (optional)
Common headers:
Content-TypeContent-LengthCache-ControlSet-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)
| GET | POST |
|---|---|
| Read data | Send data |
| Data in URL | Data in body |
| Cacheable | Not cacheable |
| Idempotent | Not idempotent |
One-liner: GET reads, POST changes.
9️⃣ ASP.NET Core Request Access
HttpContext.Request
MethodPathQueryHeadersBody
HttpContext.Response
StatusCodeHeadersWriteAsync()
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.