|
| 1 | +--- |
| 2 | +layout: default |
| 3 | +title: HTTP Methods |
| 4 | +parent: The OpenAPI Specification Explained |
| 5 | +nav_order: 10 |
| 6 | +--- |
| 7 | + |
| 8 | +# HTTP Methods |
| 9 | + |
| 10 | +OpenAPI supports describing operations using HTTP methods. This page covers the standard HTTP methods available in all OpenAPI versions, and the enhanced method support introduced in OpenAPI 3.2. |
| 11 | + |
| 12 | +## Standard HTTP Methods (All Versions) |
| 13 | + |
| 14 | +OpenAPI has always supported standard HTTP methods as operation keys in path items: |
| 15 | + |
| 16 | +```yaml |
| 17 | +paths: |
| 18 | + /users: |
| 19 | + get: # Retrieve users |
| 20 | + summary: List users |
| 21 | + responses: |
| 22 | + '200': |
| 23 | + description: User list |
| 24 | + post: # Create user |
| 25 | + summary: Create a new user |
| 26 | + responses: |
| 27 | + '201': |
| 28 | + description: User created |
| 29 | + put: # Replace user collection |
| 30 | + summary: Replace all users |
| 31 | + delete: # Delete users |
| 32 | + summary: Delete all users |
| 33 | + options: # Get allowed methods |
| 34 | + summary: Get allowed methods for users endpoint |
| 35 | + head: # Get headers only |
| 36 | + summary: Get user list headers |
| 37 | + patch: # Update users |
| 38 | + summary: Update users |
| 39 | + trace: # Diagnostic trace |
| 40 | + summary: Trace users endpoint |
| 41 | +``` |
| 42 | +
|
| 43 | +Each method corresponds to a specific HTTP verb and follows REST conventions for the expected behavior. |
| 44 | +
|
| 45 | +## Enhanced HTTP Method Support in OpenAPI 3.2 |
| 46 | +
|
| 47 | +### QUERY Method Support |
| 48 | +{: .d-inline-block } |
| 49 | +OpenAPI 3.2+ |
| 50 | +{: .label .label-green } |
| 51 | +
|
| 52 | +OpenAPI 3.2 adds native support for the [QUERY HTTP method](https://www.ietf.org/archive/id/draft-ietf-httpbis-safe-method-w-body-11.html), designed for complex queries that don't fit in URL query strings. |
| 53 | +
|
| 54 | +### QUERY Method Example |
| 55 | +
|
| 56 | +```yaml |
| 57 | +# OpenAPI 3.2 |
| 58 | +paths: |
| 59 | + /products: |
| 60 | + query: |
| 61 | + summary: Advanced product search |
| 62 | + requestBody: |
| 63 | + required: true |
| 64 | + content: |
| 65 | + application/json: |
| 66 | + schema: |
| 67 | + type: object |
| 68 | + properties: |
| 69 | + filter: |
| 70 | + type: object |
| 71 | + sort: |
| 72 | + type: array |
| 73 | + items: |
| 74 | + type: string |
| 75 | + responses: |
| 76 | + '200': |
| 77 | + description: Search results |
| 78 | +``` |
| 79 | +
|
| 80 | +### Additional Operations for Custom Methods |
| 81 | +{: .d-inline-block } |
| 82 | +OpenAPI 3.2+ |
| 83 | +{: .label .label-green } |
| 84 | +
|
| 85 | +Use `additionalOperations` for HTTP methods not covered by standard OpenAPI operations: |
| 86 | + |
| 87 | +### Additional Operations Example |
| 88 | + |
| 89 | +Add the method names in upper case, any supported HTTP method name can be used. |
| 90 | + |
| 91 | +```yaml |
| 92 | +# OpenAPI 3.2 |
| 93 | +paths: |
| 94 | + /documents/{id}: |
| 95 | + additionalOperations: |
| 96 | + LINK: |
| 97 | + summary: Link related documents |
| 98 | + parameters: |
| 99 | + - name: id |
| 100 | + in: path |
| 101 | + required: true |
| 102 | + schema: { type: string } |
| 103 | + requestBody: |
| 104 | + required: true |
| 105 | + content: |
| 106 | + application/json: |
| 107 | + schema: |
| 108 | + type: object |
| 109 | + properties: |
| 110 | + targetDocument: |
| 111 | + type: string |
| 112 | + relationship: |
| 113 | + type: string |
| 114 | + responses: |
| 115 | + '204': |
| 116 | + description: Link created successfully |
| 117 | +``` |
| 118 | + |
| 119 | +This approach makes it easier to adopt new methods as the HTTP landscape evolves. |
0 commit comments