drewlabs/laravel-http
最新稳定版本:v0.3.4
Composer 安装命令:
composer require drewlabs/laravel-http
包简介
Provides bridge to laravel framework HTTP components
README 文档
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"
统计信息
- 总下载量: 350
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2023-05-23