Downloads
Stars
Version
The drewlabs/http
package provides utility classes and functions for unified HTTP response API and middleware classes for handling CORS.
By default providers are automatically registered when running Laravel application after composer finishes installing the package.
// bootstrap/app.php
// ...
// Register the HttpService provider
$app->register(Drewlabs\Laravel\Http\HttpServiceProvider::class);
// ...
To use the cors middleware in your application add the following code to your kernel based on the framework being used:
// app/Http/Kernel.php
// ...
protected $middleware = [
// ...
\Drewlabs\Laravel\Http\Middleware\Cors::class,
];
// bootstrap/app.php
$app->middleware([
// Other globally registered middlewares...
\Drewlabs\Laravel\Http\Middleware\Cors::class,
]);
// ...
Note In order to allow any host
or method
, or headers
use the *
in the matching key of the config array.
It's a midleware that convert all empty string query parameteres and empty request body entry to null.
Note: Laravel already provide implementation for such case. But if you still want to use the current package middleware do it as follow.
// app/Http/Kernel.php
// ...
protected $middleware = [
// ...
\Drewlabs\Laravel\Http\Middleware\EmptyStringToNull::class,
];
// bootstrap/app.php
$app->middleware([
// Other globally registered middlewares...
\Drewlabs\Laravel\Http\Middleware\EmptyStringToNull::class,
]);
// ...
This configuration file contains middleware aliases keys definition for the application Http request handlers, like auth, policy middlewares.
php artisan vendor:publish --tag="drewlabs-http"