I am creating a custom route using WP API this way:
register_rest_route( 'service/v1', 'shopping', array(
'methods' => WP_REST_Server::READABLE,
'callback' => 'my_awesome_function',
));
I am writing the following function:
function my_awesome_function($request_data) {
$parameters = $request_data->get_params();
if( !isset( $parameters['product'] ) || empty($parameters['product']) ){
return array( 'error' => 'No product provided' );
}else{
$product = $parameters['product'];\
return array( 'Product' => $product );
}
}
This works perfectly fine using this structure www.example.com/wp-json/service/v1/shopping?product=perfume
However I want it to work in a RESTful way using the URL: www.example.com/wp-json/service/v1/shopping/perfume
Should I change the way I am registering the route or this is not possible and needs to be done through URL rewrite in .htaccess?