pathum4u/api_request
最新稳定版本:v2.1.0
Composer 安装命令:
composer require pathum4u/api_request
包简介
API Request for Multiple source With GuzzleHttp
README 文档
README
Simple Laravel\Lumen Micro service api request package(service to service).
Installation
composer require pathum4u/api_request
Insert in app.php
$app->register(Pathum4u\ApiRequest\ApiRequestServiceProvider::class);
publish config
php artisan vendor:publish
or
config -> services.php
<?php
return [
'user' => [
'base_uri' => env('USER_SERVICE_URI'),
'secret' => env('USER_SERVICE_SECRET')
],
'notification' => [
'base_uri' => env('NOTIFICATION_SERVICE_URI'),
'secret' => env('NOTIFICATION_SERVICE_SECRET')
],
];
Then
Limen -> app.php
$app->configure('services');
Request
use Pathum4u\ApiRequest\ApiRequest;
$client = new ApiRequest();
$client->service('notification')->post('/test', $request->all());
$client = new ApiRequest();
$client->service('notification')
->dd()
->adForm()
->post(['email'=> 'tese@tes.com']); // $request->all()
Other End
Create & Register Middleware on other end to validate each request with token. Use same key on both ends
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$allowedSecrets = explode(',', env('MY_SECRETS_TOKEN'));
if (in_array($request->header('Secret'), $allowedSecrets)) {
return $next($request);
}
//
return response()->json(['message' => 'unauthorized token'], 401);
}
Acknowledgments
This project created specific requirements for one of my projects, this may not for everyone.
Worked & Tested
Laravel/Lumen
License
Composer is licensed under the MIT License - see the LICENSE file for details.
统计信息
- 总下载量: 619
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-04