guardian360 / resonance
Resonance旨在使执行HTTP请求和获取响应变得极其简单。
1.1.0
2021-03-01 11:45 UTC
Requires
- php: >=7.0.0
- guzzlehttp/guzzle: ^6.0|^7.0
Requires (Dev)
- phpunit/phpunit: ^6.0
- symfony/var-dumper: ^3.4
This package is auto-updated.
Last update: 2024-08-29 05:06:41 UTC
README
Resonance旨在使执行HTTP请求和获取响应变得极其简单。
需求
- PHP >=7.0.0
安装
通过composer安装。
$ composer require guardian360/resonance
用法
目前,仅实现了Guzzle驱动程序。我并不一定打算自己扩展驱动程序,因为使用库中提供的Driver合约,编写自己的驱动程序非常简单。您可以使用几乎任何HTTP库简单地创建自己的驱动程序实现。
不再多说,下面是一个简单的示例。
// First, we set up a library client which we want our client to use. Here, we // are using a Guzzle client, which we can predefine beforehand with options // such as headers, cookies or multipart requests. $library = new GuzzleHttp\Client(['base_uri' => 'https://']); // Next we feed the library to the driver we'd like to use. In this case, since // we've setup a Guzzle client, we'll be using the Guzzle driver naturally. $driver = new Resonance\Drivers\Guzzle($library); // Finally we feed the driver we want to use to our client. $client = new Resonance\Client($driver); // Then we can simply perform HTTP requests and get the response body. // For example, GET requests... $response = $client->get('/'); // POST requests... $response = $client->post('/contact', [ 'email' => 'someone@example.com', 'subject' => 'Hi there', 'content' => 'Resonance is so cool, it makes everything so simple!' ]); // PUT requests... $response = $client->put('/users/1/edit', ['name' => 'Mambo Jambo']); // And DELETE requests. $response = $client->delete('/posts/1');