Download the PHP package chroma-x/json-http-client without Composer
On this page you can find all versions of the php package chroma-x/json-http-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package json-http-client
PHP JSON HTTP Client
A JSON HTTP client library. This project also is the reference implementation for extending the PHP Basic HTTP Client.
Installation
Usage
Autoloading and namesapce
Simple usage
Preparing the HTTP client
Performing requests and read the response
Body-less requests (GET, HEAD and DELETE)
Perfoming the following GET
request with additional query parameters
will result in the following HTTP request.
The same mechanic is offered to perform HEAD
and DELETE
requests wich all are body-less.
Body-full requests (POST, PUT, PATCH)
Perfoming the following POST
request with body data
will result in the following HTTP request.
The same mechanic is offered to perform PUT
and PATCH
requests wich all are body-full.
Detailed usage
The following example shows the usage with a more detailed configuration.
Configuring a HTTP Transport instance
Configuring a HTTPS Transport instance
Configuring a Message instance with Body
Message and request Header instances
Please note, that headers have some unusual behaviours. Header names have an uniform way of nomenclature so the following three getter calls would have the same result.
To allow multiple request headers using the same name, the method addAdditionalHeader
provides such a logic.
Configuring an endpoints URL, build the Request instance and perform the HTTP request
For more information about the usage of the URL object please take a look at the PHP URL Util project.
The resulting HTTP request would be the following.
Usage of authentication methods
You can add one or more Authentication instances to every Request instance. At the moment this project provides classes for HTTP Basic Authentication and SSL Client Certificate Authentication.
HTTP Basic Authentication
Required credentials are a username and a password that get provided to the class constructor as arguments.
SSL Client Certificate Authentication
Required credentials are a Certificate Authority Certificate, a Client Certificate and the password that is used to decrypt the Client Certificate that get provided to the class constructor as arguments.
Reading from the resulting Response object
Getting the response object
If using the JsonHttpClient
the response object is returned by the termination methods listed above. If directly using the JsonRequest instance, you can get the JsonResponse object via a getter.
Getting effective Request information
After successful performing the request, the effective request information is tracked back to the JsonRequest object. They can get accessed as follows.
Getting some transactional statistics
Exception handling
PHP JSON HTTP Client provides different exceptions – also provided by the PHP Common Exceptions project – for proper handling.
You can find more information about PHP Common Exceptions at Github.
Exceptions to be expected
In general you should expect that any setter method could thrown an \InvalidArgumentException
. The following exceptions could get thrown while using PHP Basic HTTP Client.
ChromaX\CommonException\IoException\FileNotFoundException
on configuring aClientCertificateAuthentication
instanceChromaX\CommonException\IoException\FileReadableException
on configuring aClientCertificateAuthentication
instanceChromaX\BasicHttpClient\Exception\HttpRequestAuthenticationException
on performing a requestChromaX\BasicHttpClient\Exception\HttpRequestException
on performing a requestChromaX\CommonException\NetworkException\ConnectionTimeoutException
on performing a requestChromaX\CommonException\NetworkException\CurlException
on performing a requestChromaX\BasicHttpClient\Exception\HttpResponseException
if parsing the JSON response body fails
Contribution
Contributing to our projects is always very appreciated.
But: please follow the contribution guidelines written down in the CONTRIBUTING.md document.
License
PHP JSON HTTP Client is under the MIT license.