What is HTTP?
HTTP (Hypertext Transfer Protocol) is the foundation of data exchange on the web. It is a request-response protocol where a client (like your Flutter app or a Python script) sends a request to a server, and the server returns a response. Understanding this flow is essential for building backends with FastAPI or integrating Gemini AI services.
The Request-Response Cycle
Every HTTP interaction consists of two parts. The Request contains the method, URL, headers, and optional body. The Response contains a status code, headers, and the data (usually JSON or HTML).
HTTP Methods (Verbs)
Methods tell the server what action to perform on the resource. While there are several, four are used in 99% of REST API development.
- GET: Retrieve data. Should never change server state.
- POST: Create new data. Usually includes a body (payload).
- PUT: Replace an existing resource entirely.
- DELETE: Remove a resource from the server.
Understanding Status Codes
Status codes are three-digit numbers issued by a server in response to a client's request. They are grouped into five classes based on the first digit.
| Range | Category | Examples |
|---|---|---|
| 2xx | Success | 200 (OK), 201 (Created) |
| 3xx | Redirection | 301 (Moved), 304 (Not Modified) |
| 4xx | Client Error | 400 (Bad Request), 401 (Unauthorized), 404 (Not Found) |
| 5xx | Server Error | 500 (Internal Server Error), 503 (Service Unavailable) |
Anatomy of a URL
A URL (Uniform Resource Locator) is the address used to find a resource. It consists of the protocol (https), domain (api.example.com), port (:443), path (/v1/users), and query parameters (?id=123).