Title: register_rest_route
Published: December 9, 2015
Last modified: August 20, 2026

---

# register_rest_route( string $route_namespace, string $route, array $args = array(), bool $override = false ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#user-contributed-notes)

Registers a REST API route.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#description)󠁿

Note: Do not use before the [‘rest_api_init’](https://developer.wordpress.org/reference/hooks/rest_api_init/)
hook.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#parameters)󠁿

 `$route_namespace`stringrequired

The first URL segment after core prefix. Should be unique to your package/plugin.

`$route`stringrequired

The base URL for route you are adding.

`$args`arrayoptional

Either an array of options for the endpoint, or an array of arrays for multiple 
methods.

Default:`array()`

`$override`booloptional

If the route already exists, should we override it? True overrides, false merges(
with newer overriding if duplicate keys exist).

Default:`false`

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

 bool True on success, false on error.

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

    ```php
    function register_rest_route( $route_namespace, $route, $args = array(), $override = false ) {
    	if ( empty( $route_namespace ) ) {
    		/*
    		 * Non-namespaced routes are not allowed, with the exception of the main
    		 * and namespace indexes. If you really need to register a
    		 * non-namespaced route, call `WP_REST_Server::register_route` directly.
    		 */
    		_doing_it_wrong(
    			__FUNCTION__,
    			sprintf(
    				/* translators: 1: string value of the namespace, 2: string value of the route. */
    				__( 'Routes must be namespaced with plugin or theme name and version. Instead there seems to be an empty namespace \'%1$s\' for route \'%2$s\'.' ),
    				'<code>' . $route_namespace . '</code>',
    				'<code>' . $route . '</code>'
    			),
    			'4.4.0'
    		);
    		return false;
    	} elseif ( empty( $route ) ) {
    		_doing_it_wrong(
    			__FUNCTION__,
    			sprintf(
    				/* translators: 1: string value of the namespace, 2: string value of the route. */
    				__( 'Route must be specified. Instead within the namespace \'%1$s\', there seems to be an empty route \'%2$s\'.' ),
    				'<code>' . $route_namespace . '</code>',
    				'<code>' . $route . '</code>'
    			),
    			'4.4.0'
    		);
    		return false;
    	}

    	$clean_namespace = trim( $route_namespace, '/' );

    	if ( $clean_namespace !== $route_namespace ) {
    		_doing_it_wrong(
    			__FUNCTION__,
    			sprintf(
    				/* translators: 1: string value of the namespace, 2: string value of the route. */
    				__( 'Namespace must not start or end with a slash. Instead namespace \'%1$s\' for route \'%2$s\' seems to contain a slash.' ),
    				'<code>' . $route_namespace . '</code>',
    				'<code>' . $route . '</code>'
    			),
    			'5.4.2'
    		);
    	}

    	if ( ! did_action( 'rest_api_init' ) ) {
    		_doing_it_wrong(
    			__FUNCTION__,
    			sprintf(
    				/* translators: 1: rest_api_init, 2: string value of the route, 3: string value of the namespace. */
    				__( 'REST API routes must be registered on the %1$s action. Instead route \'%2$s\' with namespace \'%3$s\' was not registered on this action.' ),
    				'<code>rest_api_init</code>',
    				'<code>' . $route . '</code>',
    				'<code>' . $route_namespace . '</code>'
    			),
    			'5.1.0'
    		);
    	}

    	if ( isset( $args['args'] ) ) {
    		$common_args = $args['args'];
    		unset( $args['args'] );
    	} else {
    		$common_args = array();
    	}

    	if ( isset( $args['callback'] ) ) {
    		// Upgrade a single set to multiple.
    		$args = array( $args );
    	}

    	$defaults = array(
    		'methods'  => 'GET',
    		'callback' => null,
    		'args'     => array(),
    	);

    	foreach ( $args as $key => &$arg_group ) {
    		if ( ! is_numeric( $key ) ) {
    			// Route option, skip here.
    			continue;
    		}

    		$arg_group         = array_merge( $defaults, $arg_group );
    		$arg_group['args'] = array_merge( $common_args, $arg_group['args'] );

    		if ( ! isset( $arg_group['permission_callback'] ) ) {
    			_doing_it_wrong(
    				__FUNCTION__,
    				sprintf(
    					/* translators: 1: The REST API route being registered, 2: The argument name, 3: The suggested function name. */
    					__( 'The REST API route definition for %1$s is missing the required %2$s argument. For REST API routes that are intended to be public, use %3$s as the permission callback.' ),
    					'<code>' . $clean_namespace . '/' . trim( $route, '/' ) . '</code>',
    					'<code>permission_callback</code>',
    					'<code>__return_true</code>'
    				),
    				'5.5.0'
    			);
    		}

    		foreach ( $arg_group['args'] as $arg ) {
    			if ( ! is_array( $arg ) ) {
    				_doing_it_wrong(
    					__FUNCTION__,
    					sprintf(
    						/* translators: 1: $args, 2: The REST API route being registered. */
    						__( 'REST API %1$s should be an array of arrays. Non-array value detected for %2$s.' ),
    						'<code>$args</code>',
    						'<code>' . $clean_namespace . '/' . trim( $route, '/' ) . '</code>'
    					),
    					'6.1.0'
    				);
    				break; // Leave the foreach loop once a non-array argument was found.
    			}
    		}
    	}

    	$full_route = '/' . $clean_namespace . '/' . trim( $route, '/' );
    	rest_get_server()->register_route( $clean_namespace, $full_route, $args, $override );
    	return true;
    }
    ```

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

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

| Uses | Description | 
| [rest_get_server()](https://developer.wordpress.org/reference/functions/rest_get_server/)`wp-includes/rest-api.php` |

Retrieves the current REST server instance.

  | 
| [did_action()](https://developer.wordpress.org/reference/functions/did_action/)`wp-includes/plugin.php` |

Retrieves the number of times an action has been fired during the current request.

  | 
| [__()](https://developer.wordpress.org/reference/functions/__/)`wp-includes/l10n.php` |

Retrieves the translation of $text.

  | 
| [_doing_it_wrong()](https://developer.wordpress.org/reference/functions/_doing_it_wrong/)`wp-includes/functions.php` |

Marks something as being incorrectly called.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#)

| Used by | Description | 
| [WP_REST_View_Config_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_view_config_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-view-config-controller.php` |

Registers the routes for the controller.

  | 
| [WP_REST_Icon_Collections_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_icon_collections_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-icon-collections-controller.php` |

Registers the routes for the objects of the controller.

  | 
| [WP_REST_Icons_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_icons_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-icons-controller.php` |

Registers the routes for the objects of the controller.

  | 
| [WP_REST_Abilities_V1_Categories_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_categories_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-categories-controller.php` |

Registers the routes for ability categories.

  | 
| [WP_REST_Abilities_V1_Run_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_run_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-run-controller.php` |

Registers the routes for ability execution.

  | 
| [WP_REST_Abilities_V1_List_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_abilities_v1_list_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-abilities-v1-list-controller.php` |

Registers the routes for abilities.

  | 
| [WP_REST_Font_Faces_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_font_faces_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-font-faces-controller.php` |

Registers the routes for posts.

  | 
| [WP_REST_Font_Collections_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_font_collections_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php` |

Registers the routes for the objects of the controller.

  | 
| [WP_REST_Template_Autosaves_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_template_autosaves_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-template-autosaves-controller.php` |

Registers the routes for autosaves.

  | 
| [WP_REST_Template_Revisions_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_template_revisions_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-template-revisions-controller.php` |

Registers the routes for revisions based on post types supporting revisions.

  | 
| [WP_REST_Navigation_Fallback_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_navigation_fallback_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-navigation-fallback-controller.php` |

Registers the controllers routes.

  | 
| [WP_REST_Global_Styles_Revisions_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_global_styles_revisions_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-global-styles-revisions-controller.php` |

Registers the controller’s routes.

  | 
| [WP_REST_Block_Patterns_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_block_patterns_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-block-patterns-controller.php` |

Registers the routes for the objects of the controller.

  | 
| [WP_REST_Block_Pattern_Categories_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_block_pattern_categories_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-block-pattern-categories-controller.php` |

Registers the routes for the objects of the controller.

  | 
| [WP_REST_Global_Styles_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_global_styles_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php` |

Registers the controllers routes.

  | 
| [WP_REST_URL_Details_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_url_details_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-url-details-controller.php` |

Registers the necessary REST API routes.

  | 
| [WP_REST_Menu_Locations_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_menu_locations_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-menu-locations-controller.php` |

Registers the routes for the objects of the controller.

  | 
| [WP_REST_Edit_Site_Export_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_edit_site_export_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-edit-site-export-controller.php` |

Registers the site export route.

  | 
| [WP_REST_Widgets_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_widgets_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-widgets-controller.php` |

Registers the widget routes for the controller.

  | 
| [WP_REST_Sidebars_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_sidebars_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-sidebars-controller.php` |

Registers the controllers routes.

  | 
| [WP_REST_Templates_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_templates_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php` |

Registers the controllers routes.

  | 
| [WP_REST_Pattern_Directory_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_pattern_directory_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php` |

Registers the necessary REST API routes.

  | 
| [WP_REST_Widget_Types_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_widget_types_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-widget-types-controller.php` |

Registers the widget type routes.

  | 
| [WP_REST_Site_Health_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_site_health_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-site-health-controller.php` |

Registers API routes.

  | 
| [WP_REST_Application_Passwords_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_application_passwords_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-application-passwords-controller.php` |

Registers the REST API routes for the application passwords controller.

  | 
| [WP_REST_Block_Directory_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_block_directory_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-block-directory-controller.php` |

Registers the necessary REST API routes.

  | 
| [WP_REST_Plugins_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_plugins_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php` |

Registers the routes for the plugins controller.

  | 
| [WP_REST_Block_Types_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_block_types_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php` |

Registers the routes for block types.

  | 
| [WP_REST_Attachments_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_attachments_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php` |

Registers the routes for attachments.

  | 
| [WP_REST_Search_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_search_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-search-controller.php` |

Registers the routes for the search controller.

  | 
| [WP_REST_Themes_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_themes_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php` |

Registers the routes for themes.

  | 
| [WP_REST_Autosaves_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_autosaves_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-autosaves-controller.php` |

Registers the routes for autosaves.

  | 
| [WP_REST_Block_Renderer_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_block_renderer_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-block-renderer-controller.php` |

Registers the necessary REST API routes, one for each dynamic block.

  | 
| [WP_REST_Users_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_users_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php` |

Registers the routes for users.

  | 
| [WP_REST_Revisions_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_revisions_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-revisions-controller.php` |

Registers the routes for revisions based on post types supporting revisions.

  | 
| [WP_REST_Post_Statuses_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_post_statuses_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php` |

Registers the routes for post statuses.

  | 
| [WP_REST_Settings_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_settings_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php` |

Registers the routes for the site’s settings.

  | 
| [WP_REST_Terms_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_terms_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php` |

Registers the routes for terms.

  | 
| [WP_REST_Posts_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_posts_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php` |

Registers the routes for posts.

  | 
| [WP_REST_Taxonomies_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_taxonomies_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php` |

Registers the routes for taxonomies.

  | 
| [WP_REST_Post_Types_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_post_types_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php` |

Registers the routes for post types.

  | 
| [WP_REST_Comments_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/register_routes/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Registers the routes for comments.

  | 
| [WP_oEmbed_Controller::register_routes()](https://developer.wordpress.org/reference/classes/wp_oembed_controller/register_routes/)`wp-includes/class-wp-oembed-controller.php` |

Register the oEmbed REST API route.

  |

[Show 38 more](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#)

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

| Version | Description | 
| [5.5.0](https://developer.wordpress.org/reference/since/5.5.0/) | Added a `_doing_it_wrong()` notice when the required `permission_callback` argument is not set. | 
| [5.1.0](https://developer.wordpress.org/reference/since/5.1.0/) | Added a `_doing_it_wrong()` notice when not called on or after the `rest_api_init` hook. | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

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

 1.   [Skip to note 9 content](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#comment-content-4379)
 2.    [alordiel](https://profiles.wordpress.org/alordiel/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-4379)
 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%2Ffunctions%2Fregister_rest_route%2F%23comment-4379)
     Vote results for this note: 20[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%2Ffunctions%2Fregister_rest_route%2F%23comment-4379)
 4.  Since WP 5.5.0 there is a notice if your registration of REST API route is not
     including the ``permission_callback``. You may get some notice in debug.log like
     the following one:
 5.  _PHP Notice: register\_rest\_route was called **incorrectly**. The REST API route
     definition for `/foo` is missing the required `permission\_callback` argument.
     For REST API routes that are intended to be public, use `\_\_return\_true` as 
     the permission callback._
 6.  To solve this problem you will need to add the ``permission_callback`` in arguments
     like the example from the **“Routes and Endpoints Handbook”**: [https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/#permissions-callback](https://developer.wordpress.org/rest-api/extending-the-rest-api/routes-and-endpoints/#permissions-callback)
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_rest_route%2F%3Freplytocom%3D4379%23feedback-editor-4379)
 8.   [Skip to note 10 content](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#comment-content-1459)
 9.    [Lance Cleveland](https://profiles.wordpress.org/charlestonsw/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-1459)
 10. [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%2Ffunctions%2Fregister_rest_route%2F%23comment-1459)
     Vote results for this note: 17[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%2Ffunctions%2Fregister_rest_route%2F%23comment-1459)
 11. Args is a named array that usually includes the keys ‘methods’ and ‘callback’.
 12. ‘method’ defines which HTTP methods are to be processed by the function defined
     by ‘callback’.
 13. ‘method’ can be a string of comma-separated HTTP methods or an array of strings
     of HTTP methods.
 14. A common practice is to use the [WP_REST_Server](https://developer.wordpress.org/reference/classes/wp_rest_server/)
     constants to set the ‘method’.
 15. WP_REST_Server::READABLE = ‘GET’
 16. WP_REST_Server::EDITABLE = ‘POST, PUT, PATCH’
 17. WP_REST_Server::DELETABLE = ‘DELETE’
 18. WP_REST_Server::ALLMETHODS = ‘GET, POST, PUT, PATCH, DELETE’
 19. **Example**
 20. `
      // Get a list of locations. // Method GET via wp-json/store-locator-plus//locations/////
     Calls the get_locations method of the current class when the route is matched.//
     register_rest_route( 'my-plugin-slug/v2' , '/locations/', array( 'methods' => '
     GET', 'callback' => array( $this, 'get_locations' ) ) );
 21.  * The CREATABLE constant was also added in same version 4.4.0. `WP_REST_Server::
        CREATABLE` = ‘POST’
      * [Brennan Goewert](https://profiles.wordpress.org/bgoewert/) [4 years ago](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-5946)
 22.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_rest_route%2F%3Freplytocom%3D1459%23feedback-editor-1459)
 23.  [Skip to note 11 content](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#comment-content-1663)
 24.   [abellowins](https://profiles.wordpress.org/abellowins/)  [  10 years ago  ](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-1663)
 25. [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%2Ffunctions%2Fregister_rest_route%2F%23comment-1663)
     Vote results for this note: 9[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%2Ffunctions%2Fregister_rest_route%2F%23comment-1663)
 26.     ```php
         //The Following registers an api route with multiple parameters. 
         add_action( 'rest_api_init', 'add_custom_users_api');
     
         [php]function add_custom_users_api(){
             register_rest_route( 'mmw/v1', '/users/market=(?P<market>[a-zA-Z0-9-]+)/lat=(?P<lat>[a-z0-9 .\-]+)/long=(?P<long>[a-z0-9 .\-]+)', array(
                 'methods' => 'GET',
                 'callback' => 'get_custom_users_data',
             ));
         }
         ```
     
 27. Make sure that your regex expressions are fine. If the data does not match then
     the URL will return a 404.
      Some examples are:
 28. (?P[a-zA-Z0-9-]+) for slug (you can change slug for your custom name)
      (?P\d+)
     for id (?P[a-z0-9 .\-]+) for longitude or latitude
 29.     ```php
         //Customize the callback to your liking
         function get_custom_users_data($data){
             //get users by market
             $users = mmw_get_custom_users();
             foreach ($users as $key => $user) {
                 $market = $user['Market'];
                 $long = $user['long'];
                 $lat = $user['lat'];
     
                 if( intval($market) === intval(trim($data['market'])) ){
                     $result[] = array(
                         'user_login' => $user->user_login,
                         'avatar_url' => get_avatar_url($user->ID),
                         'lat' => $lat,
                         'long' => $long
                     );
                 }
             }
             return $result;
         }
         ```
     
 30. _Edited to remove an extra `)` in one of the regexes. – DevHub Team_
 31.  * After version 5.5.0 **permission callback** is **required**. If you did not
        pass the permission callback in $args Then you can see the below error. _register\
        _rest\_route was called incorrectly. The REST API route definition for $route
        is missing the required permission\_callback argument. For REST API routes 
        that are intended to be public, use \_\_return\_true as the permission callback.
        Please see Debugging in WordPress for more information. (This message was added
        in version 5.5.0.)_ **Here I have shared the example for your reference:**
      *     ```php
            // Pass this action in your __construct of your class. add_action( 'rest_api_init', array( $this, 'action__rest_api_init' ) );  /**  * [action__rest_api_init description]  *  * @return {[type]} [description]  */ function action__rest_api_init() { 	register_rest_route( 		'licences', // $namespace  		'/removed', // $route 		array( 			'callback' =&gt;  array( $this, 'api__removed' ), 			'permission_callback' =&gt; '__return_true', 		) 	); }  /**  * [api__removed description]  *  * @return {[type]} [description]  */ function api__removed() { 	// do you code }
            ```
        
      *  **Note:** – licences and /removed only use for example.
      * [Jagir Bahesh](https://profiles.wordpress.org/jagirbahesh/) [6 years ago](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-4398)
 32.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_rest_route%2F%3Freplytocom%3D1663%23feedback-editor-1663)
 33.  [Skip to note 12 content](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#comment-content-4782)
 34.   [derhans](https://profiles.wordpress.org/derhans/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-4782)
 35. [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%2Ffunctions%2Fregister_rest_route%2F%23comment-4782)
     Vote results for this note: 9[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%2Ffunctions%2Fregister_rest_route%2F%23comment-4782)
 36. In case you are a friend of type hinting and are wondering what is being passed
     to your `callback` method, it’s a `WP_REST_Request` object. It might help you 
     with autocompletion and discovering other methods provided.
 37.     ```php
         public function wpdocs_get_lineitems( WP_REST_Request $data ) {
         	$params = $data->get_url_params();
         	// etc.
         }
         ```
     
 38.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_rest_route%2F%3Freplytocom%3D4782%23feedback-editor-4782)
 39.  [Skip to note 13 content](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#comment-content-1460)
 40.   [Lance Cleveland](https://profiles.wordpress.org/charlestonsw/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-1460)
 41. [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%2Ffunctions%2Fregister_rest_route%2F%23comment-1460)
     Vote results for this note: 6[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%2Ffunctions%2Fregister_rest_route%2F%23comment-1460)
 42. Args , the named array cited above, can also contain an optional ‘args’ array 
     of its own.
 43. The second args array contains the default arguments, required arguments, validation
     callback, and sanitization callback that are in place for each argument passed
     in with the REST request. The key name of this array is the name of the parameter
     being passed.
 44. See [http://v2.wp-api.org/extending/adding/](http://v2.wp-api.org/extending/adding/)
     under the “Arguments” section for more information and examples.
 45. **Example**
      ` <?php add_action( 'rest_api_init', function () { register_rest_route('
     myplugin/v1', '/author/(?P\d+)', array( 'methods' => 'GET', 'callback' => 'my_awesome_func','
     args' => array( 'id' => array( 'validate_callback' => function($param, $request,
     $key) { return is_numeric( $param ); } ), ), ) ); } );
 46.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_rest_route%2F%3Freplytocom%3D1460%23feedback-editor-1460)
 47.  [Skip to note 14 content](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#comment-content-4788)
 48.   [Keramot UL Islam](https://profiles.wordpress.org/sourav926/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-4788)
 49. [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%2Ffunctions%2Fregister_rest_route%2F%23comment-4788)
     Vote results for this note: 5[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%2Ffunctions%2Fregister_rest_route%2F%23comment-4788)
 50. 1. You can not use `/` (slash) at the beginning or end of the namespace, for example:`
     plugin_name/api/`.
      2. `permission_callback` is required argument of `register_rest_route`.
 51.     ```php
         function plugin_name_create_route() {
                 add_action( 'rest_api_init', function() {
                     register_rest_route( 'plugin_name/api', '/token/', array(
                         'methods' => 'POST',
                         'callback' =>  'plugin_name_route_api',
                         ‘permission_callback' => function() { return ''; }
                     ) );
                 } );
          }
         ```
     
 52. 1. Callback takes the request object as a parameter.
      2. You can set the response
     headers with `WP_Error` class.
 53.     ```php
         function plugin_name_route_api( \WP_REST_Request $req ) {
         	$token = get_option('bearer_token');
         	$headers = $req->get_headers();
         	$auth_token = $headers['authorization'][0];
     
         	if ( $token != $auth_token ) {
         		return new WP_Error( '401', esc_html__( 'Not Authorized', 'text_domain' ), array( 'status' => 401 ) );
         	}
     
         	return json_encode(["message" => "Authorized"]);
         }
         ```
     
 54.  * Returning the empty string in the `permission_callback` is equivalent to granting
        access. Using `'__return_true'` is preferred if the intention is to make an
        API public.
      * [Roy Orbitson](https://profiles.wordpress.org/lev0/) [3 years ago](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-6526)
 55.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_rest_route%2F%3Freplytocom%3D4788%23feedback-editor-4788)
 56.  [Skip to note 15 content](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#comment-content-2272)
 57.   [Mustafa Uysal](https://profiles.wordpress.org/m_uysl/)  [  9 years ago  ](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-2272)
 58. [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%2Ffunctions%2Fregister_rest_route%2F%23comment-2272)
     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%2Ffunctions%2Fregister_rest_route%2F%23comment-2272)
 59. for the non-namespaced routing, call `WP_REST_Server::register_route` directly.
     **
     Example**
 60.     ```php
         add_action( 'rest_api_init', function ( $server ) {
         	$server->register_route( 'foo', '/foo', array(
         		'methods'  => 'GET',
         		'callback' => function () {
         			return 'baz';
         		},
         	) );
         } );
         ```
     
 61. will register `foo` endpoint without namespace. You can access `http://example.
     com/wp-json/foo`
      As a reminder, please ensure before registering non-namespaced
     routes. They can be useful for backward compatibility only.
 62.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_rest_route%2F%3Freplytocom%3D2272%23feedback-editor-2272)
 63.  [Skip to note 16 content](https://developer.wordpress.org/reference/functions/register_rest_route/?output_format=md#comment-content-6525)
 64.   [Roy Orbitson](https://profiles.wordpress.org/lev0/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/register_rest_route/#comment-6525)
 65. [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%2Ffunctions%2Fregister_rest_route%2F%23comment-6525)
     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%2Ffunctions%2Fregister_rest_route%2F%23comment-6525)
 66. The `permission_callback` should return one of `false`, `null`, or a `WP_Error`
     if access is to be disallowed. Anything else, including other “falsey” values,
     will grant access.
 67.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fregister_rest_route%2F%3Freplytocom%3D6525%23feedback-editor-6525)

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