Skip to content
Tutorials Center
My learning

Topics

HTML Reference ยท Characters and Codes

HTTP Request Methods

HTTP request methods explained: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS, CONNECT and TRACE, which are safe or idempotent, and what forms can send.

Every HTTP request names a method (sometimes called a verb) that says what the client wants to do with the resource at the URL: read it, create something, replace it, delete it, and so on. Method names are case-sensitive and written in uppercase.

TEXT
POST /comments HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded

author=Ana&text=Nice+article

Clicking a link, loading an image or typing a URL always sends GET. An HTML form sends GET or POST. Every other method needs JavaScript (fetch()) or a non-browser client.

Methods at a glance

Method Purpose Request body Safe Idempotent Cacheable HTML forms
GET Read a resource No Yes Yes Yes Yes (method="get", the default)
HEAD Read only the headers of a GET No Yes Yes Yes No
POST Submit data to be processed; create something Yes No No Rarely* Yes (method="post")
PUT Create or replace the resource at this URL Yes No Yes No No
PATCH Change part of a resource Yes No No No No
DELETE Remove the resource Rarely No Yes No No
OPTIONS Ask which methods and features are allowed Optional Yes Yes No No
CONNECT Open a tunnel through a proxy (for HTTPS) No No No No No
TRACE Echo the request back for debugging No Yes Yes No No

* A POST response can be cached only when it carries explicit freshness information, and in practice browsers and CDNs don't do it.

  • Safe means the request does not change anything on the server (beyond logs or counters). Crawlers, prefetchers and link previews may send safe requests freely, so never make a GET link delete or buy something.
  • Idempotent means sending the same request twice has the same effect as sending it once. Clients and proxies may retry idempotent requests automatically after a network error. Deleting the same item twice still leaves it deleted; posting the same comment twice creates two comments.
  • Cacheable means a response may be stored and reused for later identical requests.

Try it

A form's method decides where the data goes. With GET it is added to the URL; with POST it travels in the request body. This example shows both without sending anything.

GET vs POST in a form

Choose put and submit: the browser does not support it in forms, so form.method falls back to get.

The methods in detail

GET

Retrieves a representation of the resource. It is the default for links, images, scripts, stylesheets and forms. Data can only travel in the URL (the query string), so it ends up in history, bookmarks, server logs and Referer headers. Use it for searches, filters and anything a user may want to bookmark or share. A body on a GET request has no defined meaning and fetch() refuses to send one.

Identical to GET, but the server returns only the status line and headers, never a body. Useful to check whether a URL exists, how big a file is (Content-Length) or whether it changed (Last-Modified, ETag) without downloading it.

POST

Sends data for the server to process: submit a form, add a comment, log in, upload a file, place an order. The meaning is up to the server, which is why POST is neither safe nor idempotent. Browsers warn before resending a POST on reload; answer successful form posts with a 303 See Other redirect to avoid that.

PUT

Stores the request body at the target URL, creating it or replacing it completely. Because the result is the same no matter how often you send it, PUT is idempotent. Common in REST APIs (PUT /users/42).

PATCH

Applies a partial change, such as updating one field. The body describes the change, for example in JSON Merge Patch (application/merge-patch+json) or JSON Patch format. Defined in RFC 5789 rather than the core HTTP standard.

DELETE

Removes the resource at the URL. Idempotent: after the first success, repeats change nothing (they may return 404, which is fine).

OPTIONS

Asks the server what it supports for a URL; the answer lists methods in the Allow header. Browsers send it automatically as the CORS preflight before cross-origin requests that use methods other than GET, HEAD or POST, or that carry custom headers.

CONNECT

Asks a proxy to open a raw two-way tunnel to another host, typically so HTTPS traffic can pass through it. Web pages cannot send it.

TRACE

Makes the server echo the received request back, to see what proxies changed. Usually disabled on servers for security reasons, and browsers refuse to send it from fetch().

Methods and HTML forms

method value What happens
get (default) Form data is encoded into the query string of the action URL.
post Form data is sent in the request body, encoded according to enctype.
dialog Nothing is sent. Inside a <dialog>, submitting closes the dialog and sets its returnValue.
anything else Invalid; treated as get.
  • A submit button can override the form's method with formmethod, for example <button formmethod="post">.
  • Frameworks emulate PUT, PATCH and DELETE in forms with a hidden field, such as <input type="hidden" name="_method" value="DELETE"> in a POST form; the server reads it and routes the request accordingly.
  • Use post for anything that changes data or contains passwords or personal information, and get for searches and filters.
HTML
<form action="/comments/7" method="post">
  <input type="hidden" name="_method" value="DELETE">
  <button>Delete comment</button>
</form>

Sending other methods with JavaScript

JavaScript
await fetch('/api/users/42', {
  method: 'PATCH',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Ana' }),
});

fetch() accepts any method name except CONNECT, TRACE and TRACK, which it blocks. It uppercases delete, get, head, options, post and put for you, but sends patch exactly as written, and many servers reject a lowercase patch. Always write methods in uppercase.