The API Router wires a clean REST API on top of the WordPress REST infrastructure. All routes live under theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Ahondev/portfolio-v2/llms.txt
Use this file to discover all available pages before exploring further.
api/v1 namespace and are accessible at /api/v1/{path} thanks to the rewrite rule added by AppServiceProvider. ApiRoute is the static facade you call from configuration/routes/api.php; ApiRouter is the singleton that converts your definitions into registered WordPress REST endpoints at the rest_api_init hook.
Base URL
/wp-json/api/v1/{path}. The AppServiceProvider adds a rewrite rule so the shorter /api/v1 form works without the WP prefix.
ApiRoute Facade
ApiRoute::get()
The route path relative to
api/v1, e.g. '/posts' or '/posts/{id}'. Curly-brace parameters are converted to named regex capture groups.Two-element array:
[ControllerClass::class, 'methodName']. The controller must extend ApiController.When
true, the permission callback checks is_user_logged_in(). Unauthenticated requests receive a 401. Defaults to false.ApiRoute::post() / ::put() / ::patch() / ::delete()
All share the same signature as get() and differ only in the registered HTTP verb.
ApiRoute::group()
Prepend a common prefix to an array of existing route definitions.
Path segment to prepend, e.g.
'/v2'.Array of
ApiRouteDefinition objects returned by earlier ApiRoute::*() calls.ApiRouteDefinition
The object returned by everyApiRoute::*() method. Chain ->middlewares() to attach request guards.
->middlewares()
An array of middleware class names (strings) or pre-instantiated middleware objects. Each class must implement
BaseMiddleware.self for chaining.
Properties
| Property | Type | Description |
|---|---|---|
$routeID | string | Base64-encoded composite of HTTP method + path; used internally as a unique key |
$httpMethod | HttpMethod | Enum value: GET, POST, PUT, PATCH, DELETE |
$path | string | The registered path (may be mutated by group()) |
$controller | string | Fully-qualified controller class name |
$method | string | Controller method to invoke |
$auth | bool | Whether WordPress login is required |
$middlewares | array | Accumulated middleware class names / instances |
Wildcard Path Parameters
Use{paramName} in your path string. The router converts it to the WP REST named-capture syntax automatically:
WP_REST_Request object:
Authentication
Pass$auth = true to lock a route to logged-in WordPress users:
is_user_logged_in() returns false, WordPress automatically returns a 401 Unauthorized JSON error.
Middleware
Middleware classes run inside thepermission_callback of register_rest_route. They execute before the controller method and can abort the request with a WP_Error or a boolean false.
Interface
The incoming REST request object, giving access to headers, body, and route params.
true— allow the request to continuefalse— reject with a generic403 ForbiddenWP_Error— reject with the specific error code and message you provide
HealthAuthGuard Example
This guard ships with the framework and protects health-check endpoints with a Bearer token read from the environment.
Custom Middleware with WP_Error
ApiController Base Class
All API controllers extendApiController, which provides three helper methods:
Complete Routes File Example
ApiRouter Internal Reference
ApiRouter is instantiated by the Kernel at rest_api_init priority 30. The instance is stored statically so ApiRoute::*() calls made inside configuration/routes/api.php can reach it via ApiRouter::instance().