Documentation Index
Fetch the complete documentation index at: https://docs.apivalk.com/llms.txt
Use this file to discover all available pages before exploring further.
Properties
ARoute instance contains the following information:
- URL: The path template for the endpoint (e.g.,
/api/v1/users/{id}). - Method: An implementation of
MethodInterfacerepresenting the allowed HTTP verb (GET, POST, etc.). - Description: An optional human-readable description used for documentation (OpenAPI).
- Tags: A collection of
TagObjectinstances used for grouping endpoints in documentation. - Security Requirements: A
RouteAuthorizationinstance defining the authentication and authorization needed for the route. - Rate Limit: An optional
RateLimitInterfaceimplementation defining the rate limiting rules for the endpoint. - Sorting: A collection of
Sortinstances defining allowed sorting fields for the endpoint. - Pagination: A
Paginationinstance defining the pagination strategy (Page, Offset, or Cursor). - Filtering: A collection of
FilterInterfaceinstances defining allowed filtering fields for the endpoint.
Path Parameters
Routes support dynamic path parameters using the{parameterName} syntax. For example:
Security and Authorization
Security requirements are defined on a per-route basis using theRouteAuthorization object. This allows you to specify which authentication scheme (e.g., Bearer, OAuth2) is required and what granular scopes and permissions the user must have.
Public Route
If noRouteAuthorization is provided (default), the route is fully public. Anyone can access it.
Authenticated Route (No Specific Scopes)
To require authentication without enforcing specific scopes or permissions, pass only the security scheme name. TheSecurityMiddleware will reject anonymous users with a 401 Unauthorized but allow any authenticated identity through.
Scoped Route (Specific Scopes and Permissions)
To require both authentication and specific scopes/permissions:Optional Security (Public with Identity)
If you want a route to be public but optionally use identity information when a token is provided, leaveRouteAuthorization as null. The AuthenticationMiddleware will still populate the identity if a valid token is present, so you can check $request->getAuthIdentity()->isAuthenticated() in your controller.
For more details on how the security system works, check the Security Overview.
Integration with Documentation
TheRoute class implements JsonSerializable, allowing it to be easily exported for OpenAPI (Swagger) generation. It includes helper methods for:
jsonSerialize(): Converts the route and its metadata into a format suitable for JSON export.static byJson(string $json): Hydrates aRouteobject from a JSON string, which is used when loading routes from the router cache.
Usage in Controllers
In an Apivalk application, you typically don’t instantiateRoute objects manually. Instead, you define them in your controller’s static getRoute() method:
Rate Limiting
You can add rate limiting to a route by providing a rate limit object as the last argument to theRoute constructor:
Sorting
You can define which fields are allowed for sorting by using thesorting() method. This takes an array of Sort objects:
sorting() method also defines the default sorting for the route. If a user does not provide an order_by query parameter, the sorting() bag on the request object will be automatically populated with these defined values.
Pagination
You can enable pagination for a route using thepagination() method. This takes a Pagination object:
page, limit, offset, or cursor query parameters and includes them in the OpenAPI documentation. See the Pagination guide for more details.
Resource Routes
For CRUD endpoints against anAbstractResource, use Route::resource() to build a route pre-configured for one of the five resource modes. It derives the URL, HTTP method, and default configuration from the resource:
Route::resource() yourself — AbstractResourceController::getRoute() does it for you. See Resources.
Filtering
You can define which fields are allowed for filtering by using thefiltering() method. This takes an array of FilterInterface instances:
filtering() method also defines the allowed filters for the route. Only configured filters will be automatically resolved from the query string and documented in OpenAPI. See the Filtering guide for more details.