About

The http method 1) is a mandatory header of http request that defines the type of operation.

Example

A minimal get request from this page

GET https://datacadamia.com/web/http/method HTTP/1.1
Host: datacadamia.com

Usage

Example of definition of:

openapi: 3.0.0
paths:
  /pet/findByStatus:
    get:
      tags:
        - pet
      summary: Finds Pets by status
      description: Multiple status values can be provided with comma separated strings
      operationId: findPetsByStatus
      parameters:
        - name: status
          in: query
          description: Status values that need to be considered for filter
          required: true
          style: form
          explode: false
          deprecated: true
          schema:
            type: array
            items:
              type: string
              enum:
                - available
                - pending
                - sold
              default: available
      responses:
        '200':
          description: successful operation
          content:
            application/xml:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pet'
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Pet'

List

HTTP defines a set of operations. By order of most frequent:

Method UnSafe
Change state ?
Description Cached by default Html element Request Body Used May be cached
GET No (Default) Transfer a current representation of the target resource.
Commonly used to download web pages
A GET request retrieve data.
GET requests will never cause an update or change to your data because they’re safe and idempotent.
Yes Html, Img, Link No Yes
POST Yes Perform resource-specific processing on the request payload.
Commonly used to transmit form submission data to a web server.
A POST request creates generally new resources..
No Form Yes No
PATCH Yes Update a resource
With PATCH requests, you only need to provide the data you want to change
No
PUT Yes Replace all current representations of the target resource with the request payload.
Create or update a resource
May be used for Data syncing
No No
HEAD No Same as GET, but only transfer the status line and header section. No No
DELETE Yes Remove all current representations of the target resource No No
CONNECT No Establish a tunnel to the server identified by the target resource. No No
OPTIONS No Describe the cross communication options for the target resource. No No
TRACE No Perform a message loop-back test along the path to the target resource. No No

Other protocols based on HTTP can define additional methods.

All general-purpose servers MUST support the methods GET and HEAD. All other methods are OPTIONAL.

A request method is considered idempotent

Syntax

The syntax is defined in the section 3.1.1. Request Line

In a http message

method         = token

where token defines the method

Management

Allowed

The set of methods allowed by a target resource can be listed in an Allow header field (Section 7.4.1).

However, the set of allowed methods can change dynamically.

When a request method is received that is:

  • unrecognized or not implemented by an origin server, the origin server SHOULD respond with the 501 (Not Implemented) status code.
  • known by an origin server but not allowed for the target resource, the origin server SHOULD respond with the 405 (Method Not Allowed) status code.

Safe/Unsafe

Safe request have methods that does not changes state while unsafe request does.