Rest API
config/rest-api.php
This file contains the configuration for the rest api. You can enabled/disable the rest api (theme routes) and register custom routes.
enabled
Section titled “enabled”This option enables/disables the rest api. If you disable the rest api, the theme routes will not be registered. Default is false.
routes
Section titled “routes”This option allows you to register custom routes. To register a route, you need to add a new array item to the routes array.
This is how the configuration works:
<?php
'routes' => [ 'namespace' => [ 'route' => [ 'methods' => HTTPMethods::GET, 'callback' => 'callback_function', ] ]]For the callback function, you can use a anonymous function, a function name or a class method (recommended).
Permissions callback
Section titled “Permissions callback”You can also add a permission_callback to the route. This callback will be called before the route callback is called.
'route' => [ 'methods' => HTTPMethods::GET, 'callback' => 'callback_function', 'permission_callback' => function () { return current_user_can('edit_posts'); }];Read more about this here: Permissions callback
Arguments
Section titled “Arguments”You can also add arguments to the route. These arguments will be passed to the callback function.
'route' => [ 'methods' => HTTPMethods::GET, 'callback' => 'callback_function', 'args' => [ 'id' => [ 'required' => true, 'validate_callback' => function ($param, $request, $key) { return is_numeric($param); } ] ]];Read more about this here: Arguments

