Get Started | Installation | Configuration | Endpoints | Attributes | Commands |
The Laravel Fast Endpoints (LFE) package allows for a variety of configurations to suit your project’s needs. You can configure the package by modifying the fast-endpoints.php
configuration file. Below is a detailed explanation of each configuration option along with code examples.
dist
This option defines the base directory where the fast-endpoints package will start scanning for endpoint classes. Ensure that all your endpoint classes are located within or under this directory so they are automatically detected and registered.
'dist' => app_path('Http/Endpoints'),
If you place your endpoint classes in app/Http/Endpoints
, the package will scan this directory and all its subdirectories to generate routes.
prefix
The prefix
option allows you to prepend a common URI segment to all routes generated by the fast-endpoints package. This is useful for organizing your routes under a specific path, such as /api
or /v1
.
'prefix' => 'fast',
With a prefix of fast
, an endpoint defined at /users
would be accessible at /fast/users
.
If you don’t want a prefix, leave this option empty:
'prefix' => '',
domain
This option allows you to specify a domain that all fast-endpoints routes should respond to. If set to null
, the routes will be available on any domain.
'domain' => null,
To restrict routes to a specific subdomain, you might set this to:
'domain' => 'api.yourdomain.com',
middleware
This option lets you apply middleware to all fast-endpoints routes. Middleware can handle tasks like authentication, authorization, or other request filtering. If set to null
, no middleware will be applied by default.
'middleware' => null,
To apply authentication middleware to all routes:
'middleware' => ['auth'],
groups
You can define additional route groups with specific configurations such as domain, prefix, or middleware. These groups can be applied to endpoint classes using the Group attribute, allowing for more organized and manageable routes.
'groups' => null,
Define a group for admin routes:
'groups' => [
'admin' => [
'prefix' => 'admin',
'middleware' => ['auth', 'role:admin'],
],
],
Apply this group in an endpoint class:
#[Group('admin')]
class AdminDashboardEndpoint {
// Endpoint logic here...
}
namespaces
This option allows you to apply configurations automatically based on the namespaces of the endpoint classes. This ensures consistent routing configurations without needing manual grouping.
'namespaces' => null,
Define configurations for a specific namespace:
'namespaces' => [
'App\Http\Endpoints\Admin' => [
'prefix' => 'admin',
'middleware' => ['auth', 'role:admin'],
],
],
request
This configuration option specifies the default class used for handling incoming requests for Fast Endpoints.
'request' => Illuminate\Http\Request::class,
If you need to customize the request handling, you can extend the default Request
class:
'request' => App\Http\Requests\CustomRequest::class,
response
This configuration option specifies the default class used for handling responses for Fast Endpoints.
'response' => Illuminate\Http\Response::class,
To customize the response handling, extend the default Response
class:
'response' => App\Http\Responses\CustomResponse::class,
Prev - Installation | Next - Endpoints |