Hi,
I’m defining custom endpoint route using controller method, which is extending WP_REST_Controller. I’ve used this code in a custom file called api.php in my active theme.
class Slug_Custom_Route extends WP_REST_Controller {
public function register_routes() {
register_rest_route('my-route', 'my-phrase', array(
'methods' => 'POST',
'callback' => 'custom_phrase',
)
);
}
public function custom_phrase(WP_REST_Request $request) {
$param = $request['param'];
return rest_ensure_response('Hello World! This is my first REST API' . $param);
}
}
add_action('rest_api_init', 'register_routes');
It’s populating the result – 404 rest_no_route.
As I’m new to all of this, Kindly help me to resolve.
-
This reply was modified 4 years, 4 months ago by pramo15.