This documentation describes unreleased changes on the main branch.

#[RestRoute]

Attribute on methods, repeatable.

use Saij\WpAppFramework\Rest\RestRoute;

Registers a public method of a #[RestController] service as a REST route.

The route is the controller's base path followed by $path. {name} placeholders match the method parameter of the same name. Parameters typed with a service candidate are injected, a WP_REST_Request parameter receives the request, all other parameters are request arguments of the same name; their schema is derived from the parameter type, default value and #[Param].

A method returning void responds with 204 No Content.

Arguments

#[RestRoute(string $path, HttpMethod|array $methods, Permission $permission)]
ParameterTypeDefaultDescription
pathstringrequiredEmpty or starting with a slash, e.g. /{id}.
methodsHttpMethod|list<HttpMethod>requiredThe HTTP method or methods the route answers, e.g. HttpMethod::Get or [HttpMethod::Put, HttpMethod::Patch].
permissionPermissionrequiredWho may call the route: PublicAccess, Capability or Callback.