Guzzle and PSR-7
Guzzle utilizes PSR-7 as the HTTP message interface. This allows Guzzle to work with any other library that utilizes PSR-7 message interfaces.
Guzzle is an HTTP client that sends HTTP requests to a server and receives HTTP responses. Both requests and responses are referred to as messages.
Guzzle relies on the guzzlehttp/psr7 Composer package for its message implementation of PSR-7.
You can create a request using the GuzzleHttp\Psr7\Request class:
1. use GuzzleHttp\Psr7\Request;
3. $request = new Request('GET', 'http://httpbin.org/get');
5. // You can provide other optional constructor arguments.
6. $headers = ['X-Foo' => 'Bar'];
7. $body = 'hello!';
8. $request = new Request('PUT', 'http://httpbin.org/put', $headers, $body);
You can create a response using the GuzzleHttp\Psr7\Response class:
1. use GuzzleHttp\Psr7\Response;
3. // The constructor requires no arguments.
4. $response = new Response();
5. echo $response->getStatusCode(); // 200
6. echo $response->getProtocolVersion(); // 1.1
8. // You can supply any number of optional arguments.
9. $status = 200;
10. $headers = ['X-Foo' => 'Bar'];
11. $body = 'hello!';
12. $protocol = '1.1';
13. $response = new Response($status, $headers, $body, $protocol);
