drewlabs / laravel-http
Provides bridge to laravel framework HTTP components
Requires
- php: ^7.2|^8.0
- drewlabs/contracts: ^0.3
- drewlabs/core-helpers: ^0.3
- drewlabs/cors: ^0.2.0
- drewlabs/http-contracts: ^0.2
- drewlabs/overloadable: ^0.1.10|^0.3
- illuminate/container: ^9.0|^10.0|^11.0
- illuminate/http: ^9.0|^10.0|^11.0
- psr/http-message: ^1.0|^2.0
Requires (Dev)
- drewlabs/psr7: ^0.1.3
- drewlabs/validation: ^0.3
- nyholm/psr7: ^1.5
- phpunit/phpunit: ^9.5
Suggests
- nyholm/psr7: Required to create psr7 requests using drewlabs_create_psr7_request() global function
README
The drewlabs/http
package provides utility classes and functions for unified HTTP response API and middleware classes for handling CORS.
Providers
By default providers are automatically registered when running Laravel application after composer finishes installing the package.
- For Lumen appliation we must manually register the providers in the bootstrap/app.php:
// bootstrap/app.php // ... // Register the HttpService provider $app->register(Drewlabs\Laravel\Http\HttpServiceProvider::class); // ...
Cors Middleware
To use the cors middleware in your application add the following code to your kernel based on the framework being used:
- Laravel
// app/Http/Kernel.php // ... protected $middleware = [ // ... \Drewlabs\Laravel\Http\Middleware\Cors::class, ];
- Lumen
// 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.
EmptyStringToNull Middleware
It's a midleware that convert all empty string query parameteres and empty request body entry to null.
- Laravel
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, ];
- Lumen
// bootstrap/app.php $app->middleware([ // Other globally registered middlewares... \Drewlabs\Laravel\Http\Middleware\EmptyStringToNull::class, ]); // ...
Http package configuration
This configuration file contains middleware aliases keys definition for the application Http request handlers, like auth, policy middlewares.
- Publishing the configuration files
php artisan vendor:publish --tag="drewlabs-http"