Download the PHP package johnshopkins/http-exchange without Composer
On this page you can find all versions of the php package johnshopkins/http-exchange. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download johnshopkins/http-exchange
More information about johnshopkins/http-exchange
Files in johnshopkins/http-exchange
Package http-exchange
Short Description A collection of PHP HTTP client adapters to make swapping out HTTP client dependencies quick and easy.
License MIT
Homepage https://github.com/johnshopkins/http-exchange
Informations about the package http-exchange
HTTP Exchange
A collection of PHP HTTP client adapters to make swapping out HTTP client dependencies quick and easy.
Available adapters:
Requirements
- PHP >= 8.0
- Guzzle >= 6.5
Installation
To install the library, you will need to use Composer in your project.
Basic usage
Single request
Batch requests
Error handling
Single request
If a request fails, a HttpExchange\Exceptions\HTTP
exception is thrown. See the exception methods documentation for more information.
Batch requests
Instead of throwing a HttpExchange\Exceptions\HTTP
when any one of the requests in a batch request fails, the exception is instead returned. This allows your application to gracefully handle failed requests, while processing successful ones.
Alternatively, you can check which kind of object was returned from each request (HttpExchange\Response
or HttpExchange\Exceptions\HTTP
) and proceed accordingly:
Documentation
Initialization
Guzzle 6
Guzzle 7
Adapter methods
batch(array $requests)
Send multiple requests concurrently.
Returns: array containing the result of each request. A HttpExchange\Response
object indicates a successful request while a HttpExchange\Exceptions\HTTP
exception object indicates a failed request.
Arguments:
-
$requests
: An array of requests to make concurrently. Format:
get(array $requests)
Make a GET request.
Returns: A HttpExchange\Response
object. Throw a HttpExchange\Exceptions\HTTP
exception object if the request fails.
Arguments:
$method
: HTTP method$uri
: Request URI$request_options
: Request options to pass to HTTP client (Guzzle 6 or Guzzle 7)
post(array $requests)
Make a POST request.
Returns: A HttpExchange\Response
object. Throw a HttpExchange\Exceptions\HTTP
exception object if the request fails.
Arguments:
$method
: HTTP method$uri
: Request URI$request_options
: Request options to pass to HTTP client (Guzzle 6 or Guzzle 7)
put(array $requests)
Make a PUT request.
Returns: A HttpExchange\Response
object. Throw a HttpExchange\Exceptions\HTTP
exception object if the request fails.
Arguments:
$method
: HTTP method$uri
: Request URI$request_options
: Request options to pass to HTTP client (Guzzle 6 or Guzzle 7)
delete(array $requests)
Make a DELETE request.
Returns: A HttpExchange\Response
object. Throw a HttpExchange\Exceptions\HTTP
exception object if the request fails.
Arguments:
$method
: HTTP method$uri
: Request URI$request_options
: Request options to pass to HTTP client (Guzzle 6 or Guzzle 7)
patch(array $requests)
Make a PATCH request.
Returns: A HttpExchange\Response
object. Throw a HttpExchange\Exceptions\HTTP
exception object if the request fails.
Arguments:
$method
: HTTP method$uri
: Request URI$request_options
: Request options to pass to HTTP client (Guzzle 6 or Guzzle 7)
head(array $requests)
Make a HEAD request.
Returns: A HttpExchange\Response
object. Throw a HttpExchange\Exceptions\HTTP
exception object if the request fails.
Arguments:
$method
: HTTP method$uri
: Request URI$request_options
: Request options to pass to HTTP client (Guzzle 6 or Guzzle 7)
options(array $requests)
Make an OPTIONS request.
Returns: A HttpExchange\Response
object. Throw a HttpExchange\Exceptions\HTTP
exception object if the request fails.
Arguments:
$method
: HTTP method$uri
: Request URI$request_options
: Request options to pass to HTTP client (Guzzle 6 or Guzzle 7)
Response methods
getBody()
Get the body of the response.
Returns: SimpleXMLElement
object if the response is XML. Object or array if the response is JSON.
getStatusCode()
Get the HTTP status code of the response;
Returns: Integer
Exception methods
All default methods available on PHP exceptions are available plus:
getStatusCode()
Get the HTTP status code of the response;
Returns: Integer