HTTP Request Methods
HTTP Request Methods
The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers.
When your browser (the client) talks to a server, it sends a request. Every request has a method that tells the server what you want to do.
The most common HTTP request methods:
| Method | What it does |
|---|---|
| GET | Read or fetch data |
| POST | Send new data |
| PUT | Replace existing data |
| PATCH | Change part of existing data |
| DELETE | Remove data |
GET
GET is used to retrieve data from a server. This is the most common method.
Every time you open a web page, your browser sends a GET request.
Some notes on GET requests:
- GET requests can be cached
- GET requests remain in the browser history
- GET requests can be bookmarked
- GET requests should never be used when dealing with sensitive data
- GET requests have length restrictions
POST
POST is used to send new data to the server, for example when you submit a form or post a comment.
The data sent to the server is stored in the request body of the HTTP request:
POST /test/demo_form.php HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2
Some notes on POST requests:
- POST requests are never cached
- POST requests do not remain in the browser history
- POST requests cannot be bookmarked
- POST requests have no restrictions on data length
PUT and PATCH
Both change data that already exists:
- PUT replaces the whole resource
- PATCH changes only the parts you send
DELETE
DELETE deletes the specified resource from the server.
HEAD
HEAD works like GET, but returns only the headers, not the content.
A HEAD request can read the Content-Length header to check the size of the file, without actually downloading the file.
OPTIONS
OPTIONS asks the server which HTTP methods it allows.