Download the PHP package jasonej/laravel-endpoints without Composer
On this page you can find all versions of the php package jasonej/laravel-endpoints. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jasonej/laravel-endpoints
More information about jasonej/laravel-endpoints
Files in jasonej/laravel-endpoints
Package laravel-endpoints
Short Description Single file endpoints for Laravel.
License MIT
Informations about the package laravel-endpoints
Laravel Endpoints
Single file endpoints for Laravel.
A typical Laravel endpoint is spread across a route, a form request, and a controller.
laravel-endpointscollapses all three into a single auto-discovered class: extendEndpoint, declare the route with an attribute, and handle the request in__invoke. Addrules()to validate andauthorize()to gate access, just like a form request.
Installation
You can install the package via composer:
You can publish the config file with:
Usage
Defining an endpoint
Extend Endpoint, declare a route with an attribute, and handle the request in __invoke. No need to register it
in routes/api.php as endpoints are auto-discovered.
HTTP method attributes
There is one attribute per verb (#[Get], #[Post], #[Put], #[Patch], #[Delete], and #[Options]) plus a
raw #[Route] for an explicit or multi-verb set. Route names accept a string or a BackedEnum.
The attributes are repeatable, so you can point several routes at a single handler:
Route options
Every attribute forwards the full set of route options:
| Option | Type | Maps to |
|---|---|---|
name |
string\|BackedEnum |
->name() |
middleware |
array |
->middleware() |
withoutMiddleware |
array |
->withoutMiddleware() |
wheres |
array<string, string> |
->where() |
domain |
string |
->domain() |
scopeBindings |
bool |
->scopeBindings() / ->withoutScopedBindings() |
Handling the request
Read input with the typed accessors (string(), integer(), boolean(), enum(), array(), all(), …), or
collect it into a DTO. Route-model-bound parameters are injected into __invoke just like any controller action, and
you can return an array, a resource, or a response.
Validation and authorization
Both are optional hooks that work just like a form request. Define rules() (with messages() and attributes() to
customize) to validate input, and authorize() to gate access. Validation runs when the endpoint is resolved, and a
failing authorize() throws a 403.
Configuration and discovery
The package scans the paths in config/endpoints.php for classes extending Endpoint. Publish the config to change
where it looks:
Endpoints can live anywhere under a configured path.
Route caching in production
Discovery reflects over the filesystem on every request that is not route-cached. In production, cache your routes so discovery runs once at build time instead of on every request:
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
Please see CONTRIBUTORS for more information on who contributed to the package.
License
The MIT License (MIT). Please see LICENSE for more information.
All versions of laravel-endpoints with dependencies
illuminate/contracts Version ^13.0
illuminate/routing Version ^13.0
illuminate/support Version ^13.0
illuminate/validation Version ^13.0
spatie/php-attribute-reader Version ^1.1
spatie/php-structure-discoverer Version ^2.4