The Hypertext Transfer Protocol (HTTP) is the foundation of data exchange on the web. It functions as a request-response protocol: a client (your browser) sends a request, and a server sends back a response.
In web development, you will use GET and POST about 90% of the time.
GET is used to retrieve data. Think of it like a search or a page view.
Visibility: Data is appended to the URL (e.g., mysite.com/page?id=123).
Caching: Browsers can save these requests for faster loading later.
Security: Never use GET for passwords because the data is visible in the browser history
POST is used to send data to a server to create or update a resource.
Visibility: Data is hidden in the "request body," not shown in the URL.
Capacity: There is no limit on how much data you can send (useful for file uploads)
Security: Safer than GET for sensitive data, but still requires HTTPS for true security.
| Feature | GET | POST |
|---|---|---|
| History | Remains in browser history | Not saved in history |
| Bookmarks | Can be bookmarked | Cannot be bookmarked |
| Data Length | Limited (Max ~2048 chars) | No restrictions |
| Data Type | Only ASCII characters | No restrictions (Binary allowed) |
| Visibility | Visible in URL | Not visible in URL |
Modern "RESTful" web applications use these specific methods to handle data more efficiently:
PUT: Sends data to create or update a resource. It is idempotent, meaning sending the same request 10 times results in the same outcome (it won't create 10 duplicates).
PATCH: Used for partial updates. (e.g., changing only a user's email address without sending their whole profile).
DELETE: Removes a specific resource from the server.
HEAD: Same as GET, but it only asks for the headers (info about the file), not the actual file. Great for checking if a file exists without downloading it.
OPTIONS: Asks the server which methods are allowed (useful for security and "CORS" checks).
| Method | Idempotent? | Cacheable? | Purpose |
|---|---|---|---|
| GET | Yes | Yes | Request data |
| POST | No | No | Create/Submit data |
| PUT | Yes | No | Replace/Update data |
| DELETE | Yes | No | Remove data |
| PATCH | No | No | Modify data partially |
| Feature | GET | POST |
|---|---|---|
| URL Data | Visible | Hidden |
| Security | Low (Don't use for passwords) | Higher |
| History | Saved | Not Saved |