Title: WP_REST_Request::get_method
Published: December 9, 2015
Last modified: April 28, 2025

---

# WP_REST_Request::get_method(): string

## In this article

 * [Return](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#wp--skip-link--target)

Retrieves the HTTP method for the request.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#return)󠁿

 string HTTP method.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#source)󠁿

    ```php
    public function get_method() {
    	return $this->method;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/rest-api/class-wp-rest-request.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/rest-api/class-wp-rest-request.php#L138)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/rest-api/class-wp-rest-request.php#L138-L140)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_REST_Request::is_method()](https://developer.wordpress.org/reference/classes/wp_rest_request/is_method/)`wp-includes/rest-api/class-wp-rest-request.php` |

Determines if the request is the given method.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/?output_format=md#comment-content-5139)
 2.    [caseymilne](https://profiles.wordpress.org/caseymilne/)  [  5 years ago  ](https://developer.wordpress.org/reference/classes/wp_rest_request/get_method/#comment-5139)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_request%2Fget_method%2F%23comment-5139)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_request%2Fget_method%2F%23comment-5139)
 4.  The return value (HTTP Method) is returned in full uppercase such as “POST”, “
     GET”, “PATCH”, “DELETE”. As an example in your API route callback you can check
     for the method type when you’re expecting one of several potential methods:
 5.      ```php
         if ( 'POST' === $request->get_method() ) {
     
           // Do POST specific processing.
     
         }
         ```
     
 6.  Alternatively you might use a switch to check the method such as:
 7.      ```php
         switch ( $request->method() ) {
     
           case 'POST':
             $this->do_post_processing( $request );
             break;
     
           case 'GET':
             $this->do_get_processing( $request );
             break;
     
         }
         ```
     
 8.  These examples are in the context of a callback from `register_rest_route()` which
     passes the `$request` (instance of `WP_REST_Request`) to the callback.
 9.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_request%2Fget_method%2F%3Freplytocom%3D5139%23feedback-editor-5139)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_rest_request%2Fget_method%2F)
before being able to contribute a note or feedback.