REST Routes & Endpoints

When running through the WordPress tutorial, I have to say I got completely the wrong end of the stick. Something that took several days to unwind.

The tutorial uses the example of :

register_rest_route( 'myplugin/v1', '/author/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'my_awesome_func',
'permission_callback' => '__return_true',
) );

My reading of the above was that the endpoint would be


where nn was the author id. No that is wrong. The (?P<id>\d+) is NOT describing the parameters that may be given to the endpoint. It is describing a segment of the route.

So the route defined by

'myplugin/v1', '/author/(?P<id>\d+)'

actually expands to:


where nn is the author id.

And that is good, because that is how REST conventionally works. You add ?param1=a,param2=b only when further information is required.