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 collection of
SecurityRequirementObjectinstances defining the authentication needed for the route.
Path Parameters
Routes support dynamic path parameters using the{parameterName} syntax. For example:
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: