usamamuneerchaudhary / laraclient
简化在 Laravel 中处理多个 API 的过程的软件包。
1.2
2023-03-26 12:08 UTC
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.5
- illuminate/database: >=v10.1.4
- illuminate/support: >=v10.1.4
Requires (Dev)
- orchestra/testbench: ^v8.0.4
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-08-29 08:47:13 UTC
README
简介
Lara Client 简化了在 Laravel 中处理 API 的过程,使得处理身份验证、速率限制和错误处理变得容易。它允许在中央配置文件中设置多个 API 连接,并指定每个连接的凭证。该软件包还包括一个缓存层来加速请求,以及一个日志系统来跟踪 API 请求和响应以进行调试。使用 Lara Client,开发者可以快速将多个 API 集成到他们的 Laravel 应用程序中,减少开发时间和努力,并使随着时间的推移管理 API 集成变得更加容易。
以下是一个快速示例,说明如何在模型中启用标签功能
- 此软件包支持 Laravel 10
- 最低支持 PHP v8.1
namespace App\Http\Controllers; use Usamamuneerchaudhary\LaraClient\LaraClient; class ApiController extends Controller { $client = new LaraClient('weatherapi'); $response = $client->get('current.json', ['q' => 'london']); $currentWeather = $response->getData(); $client2 = new LaraClient('geodb'); $georesponse = $client->get('countries'); $countries = $response->getData(); .... .... }
安装
您可以通过 composer 安装此软件包
composer require usamamuneerchaudhary/laraclient
运行迁移
安装软件包后,您可以通过运行迁移
php artisan migrate
发布配置文件
php artisan vendor:publish --provider="Usamamuneerchaudhary\LaraClient\LaraClientServiceProvider" --tag="config"
这将创建一个 lara_client.php
文件,您可以在其中定义多个第三方 API 连接。
服务提供者
别忘了在 app.php
中添加 ServiceProvider
\Usamamuneerchaudhary\LaraClient\LaraClientServiceProvider::class,
日志记录 & 发布视图
我们使用日志表来存储请求和响应,您可以通过以下路由访问它
http://yourwebsite.com/laraclient/logs
//to access logs for any specific endpoint
http://yourwebsite.com/laraclient/logs?endpoint=https://weatherapi-com.p.rapidapi.com/current.json
教程
测试
composer test
安全
如果您发现任何安全相关的问题,请通过电子邮件 hello@usamamuneer.me 而不是使用问题跟踪器来报告。
致谢
许可
MIT 许可证 (MIT)。请参阅 许可文件 获取更多信息。