| 1 | --- |
| 2 | title: "hx-method" |
| 3 | description: "Specifies the HTTP method for the request" |
| 4 | --- |
| 5 | |
| 6 | The `hx-method` attribute specifies the HTTP method (verb) to use for the request. |
| 7 | |
| 8 | ## Syntax |
| 9 | |
| 10 | ```html |
| 11 | <button hx-action="/api/users" hx-method="post"> |
| 12 | Create User |
| 13 | </button> |
| 14 | ``` |
| 15 | |
| 16 | ## Notes |
| 17 | |
| 18 | * Valid values: `get`, `post`, `put`, `patch`, `delete` |
| 19 | * If no method is specified, defaults to `get` |
| 20 | * `hx-method` is typically used with [`hx-action`](/reference/attributes/hx-action) |
| 21 | * The shorthand attributes like [`hx-get`](/reference/attributes/hx-get), [`hx-post`](/reference/attributes/hx-post), etc. can be used |
| 22 | instead |
| 23 | |
| 24 | ## Examples |
| 25 | |
| 26 | ```html |
| 27 | <!-- Explicit method specification --> |
| 28 | <button hx-action="/api/users/123" hx-method="delete"> |
| 29 | Delete User |
| 30 | </button> |
| 31 | |
| 32 | <!-- Equivalent using hx-delete shorthand --> |
| 33 | <button hx-delete="/api/users/123"> |
| 34 | Delete User |
| 35 | </button> |
| 36 | |
| 37 | <!-- Default to GET if no method specified --> |
| 38 | <button hx-action="/api/users"> |
| 39 | Get Users |
| 40 | </button> |
| 41 | ``` |