mirror of
https://github.com/php-fig/http-client.git
synced 2026-03-23 22:52:15 +01:00
Init commit
This commit is contained in:
4
CHANGELOG.md
Normal file
4
CHANGELOG.md
Normal file
@@ -0,0 +1,4 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file, in reverse chronological order by release.
|
||||
|
||||
19
LICENSE
Normal file
19
LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2017 PHP Framework Interoperability Group
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
14
README.md
Normal file
14
README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
PSR Http Client
|
||||
===============
|
||||
|
||||
This repository holds all interfaces/classes/traits related to
|
||||
[PSR-18](http://www.php-fig.org/psr/psr-18/).
|
||||
|
||||
Note that this is not a HTTP client implementation of its own. It is merely an
|
||||
interface that describes a HTTP client. See
|
||||
[the specification](https://github.com/php-fig/fig-standards/blob/master/proposed/http-client/http-client.md)
|
||||
for more details.
|
||||
|
||||
You can find implementations of the specification by looking for packages providing
|
||||
the [psr/simple-cache-implementation](https://packagist.org/providers/psr/http-client-implementation)
|
||||
virtual package.
|
||||
26
composer.json
Normal file
26
composer.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"name": "psr/http-client",
|
||||
"description": "Common interface for HTTP clients",
|
||||
"keywords": ["psr", "psr-18", "http", "http-client"],
|
||||
"homepage": "https://github.com/php-fig/http-client",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "PHP-FIG",
|
||||
"homepage": "http://www.php-fig.org/"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Psr\\Http\\Client\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.0.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/ClientException.php
Normal file
12
src/ClientException.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psr\Http\Client;
|
||||
|
||||
/**
|
||||
* Every HTTP client related Exception MUST implement this interface.
|
||||
*/
|
||||
interface ClientException extends \Throwable
|
||||
{
|
||||
}
|
||||
33
src/ClientInterface.php
Normal file
33
src/ClientInterface.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psr\Http\Client;
|
||||
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
interface ClientInterface
|
||||
{
|
||||
/**
|
||||
* Sends a PSR-7 request and returns a PSR-7 response.
|
||||
*
|
||||
* Every technically correct HTTP response MUST be returned as is, even if it represents a HTTP
|
||||
* error response or a redirect instruction. The only special case is 1xx responses, which MUST
|
||||
* be assembled in the HTTP client.
|
||||
*
|
||||
* The client MAY do modifications to the Request before sending it. Because PSR-7 objects are
|
||||
* immutable, one cannot assume that the object passed to ClientInterface::sendRequest() will be the same
|
||||
* object that is actually sent. For example the Request object that is returned by an exception MAY
|
||||
* be a different object than the one passed to sendRequest, so comparison by reference (===) is not possible.
|
||||
*
|
||||
* {@link https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-7-http-message-meta.md#why-value-objects}
|
||||
*
|
||||
* @param RequestInterface $request
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*
|
||||
* @throws \Psr\Http\Client\Exception If an error happens during processing the request.
|
||||
*/
|
||||
public function sendRequest(RequestInterface $request): ResponseInterface;
|
||||
}
|
||||
27
src/Exception/NetworkException.php
Normal file
27
src/Exception/NetworkException.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psr\Http\Client\Exception;
|
||||
|
||||
use Psr\Http\Client\ClientException;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
|
||||
/**
|
||||
* Thrown when the request cannot be completed because of network issues.
|
||||
*
|
||||
* There is no response object as this exception is thrown when no response has been received.
|
||||
*
|
||||
* Example: the target host name can not be resolved or the connection failed.
|
||||
*/
|
||||
interface NetworkException extends ClientException
|
||||
{
|
||||
/**
|
||||
* Returns the request.
|
||||
*
|
||||
* The request object MAY be a different object from the one passed to ClientInterface::sendRequest()
|
||||
*
|
||||
* @return RequestInterface
|
||||
*/
|
||||
public function getRequest(): RequestInterface;
|
||||
}
|
||||
27
src/Exception/RequestException.php
Normal file
27
src/Exception/RequestException.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Psr\Http\Client\Exception;
|
||||
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Psr\Http\Client\ClientException;
|
||||
|
||||
/**
|
||||
* Exception for when a request failed.
|
||||
*
|
||||
* Examples:
|
||||
* - Request is invalid (eg. method is missing)
|
||||
* - Runtime request errors (like the body stream is not seekable)
|
||||
*/
|
||||
interface RequestException extends ClientException
|
||||
{
|
||||
/**
|
||||
* Returns the request.
|
||||
*
|
||||
* The request object MAY be a different object from the one passed to ClientInterface::sendRequest()
|
||||
*
|
||||
* @return RequestInterface
|
||||
*/
|
||||
public function getRequest(): RequestInterface;
|
||||
}
|
||||
Reference in New Issue
Block a user