bitstone / guzzle-wrapper
该软件包已被废弃,不再维护。作者建议使用Laravel 7.0实现的自己的HttpClient软件包。
一个围绕Guzzle客户端API的Laravel包装器。
v1.8
2019-09-20 13:02 UTC
Requires
- php: ^7.0
- guzzlehttp/guzzle: ~6.0
- illuminate/support: ~5.4
Requires (Dev)
- mockery/mockery: 0.9
- phpunit/phpunit: 6.*
README
这是一个简单的Guzzle HTTP请求包装器,以便更容易地使用头部进行HTTP调用。
安装
使用Composer安装此软件包
composer require bitstone/guzzle-wrapper or add the library to your composer.json file: "bitstone/guzzle-wrapper": "^1.6"
然后您需要更新config/app.php中的服务提供者数组
Bitstone\GuzzleWrapper\HttpServiceProvider::class
以及外观别名
'Http' => Bitstone\GuzzleWrapper\Http::class
使用方法
Http::request('GET', http://example.com/api/v1/users', ['role' => 'admin'], ['Content-Type' => 'application/json']);
或者
Http::request('GET', http://example.com/api/v1/users?role=admin', [], ['Content-Type' => 'application/json']);
Http::request('POST', http://example.com/api/v1/users', ['option' => 'value'], ['Content-Type' => 'application/json', 'Accept' => 'application/json']);
但也可以调用特定的HTTP方法
Http::get('http://example.com/api/v1/users');
Http::post('http://example.com/api/v1/users/1', ['option' => 'value'], ['Accept' => 'application/json']);
Http::put('http://example.com/api/v1/users/1', ['option' => 'another value'], ['Accept' => 'application/json']);
Http::delete('http://example.com/api/v1/users/1');
Http::head('http://example.com/api/v1/users/1');