Download the PHP package dogado/json-api-client without Composer
On this page you can find all versions of the php package dogado/json-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dogado/json-api-client
More information about dogado/json-api-client
Files in dogado/json-api-client
Package json-api-client
Short Description Abstract client side php implementation of the JSON:API protocol.
License MIT
Homepage https://github.com/dogado-group/json-api-client
Informations about the package json-api-client
Abstract client side php implementation of the JSON:API protocol.
Installation
It's recommended to install guzzlehttp/guzzle
version ^7.0
as http-client and http-interop/http-factory-guzzle
for PSR-17 compatible factories.
You can also use any other HTTP client which implements PSR-18.
Usage
First you should read the docs of dogado/json-api-common where all basic structures will be explained.
Your API client is an instance of Dogado\JsonApi\Client\JsonApiClient
, which requires a PSR-18 HTTP client (Psr\Http\Client\ClientInterface
) to execute requests.
Action Pattern
In most cases it's easier to capsule request scenarios into single classes since every request has its own requirements.
In this package this is called Action
. To make things easier, we already defined an AbstractAction
class under the
Dogado\JsonApi\Client\Action
namespace. An example how to create such an action can be found
in the tests.
When fetching resources in actions it's also very common to filter, paginate and sort. To define these options within Actions,
there are multiple Traits you can use, defined in the same namespace as the AbstractAction
class.
Authentication
When using a JSON:API client to access a server application you will probably need to be authenticated. As this a common
use case, this client offers native support for authentication as so called "AuthenticationMiddleware" represented by
an interface. The client provides a native set of authentication mechanisms: OAuth2 client credentials and HTTP basic
auth, but you can create a custom middleware yourself based on the AuthenticationMiddlewareInterface
if that doesn't
fit your needs or feel free to create a pull request to add
more authentications.
OAuth2
The AuthenticationMiddleware
class requires a Dogado\JsonApi\Client\Model\OAuth2Credentials
instance which
contains an access token, the token type and the expiration date. You can either create an instance yourself and insert
the required data or use the Dogado\JsonApi\Client\Service\OAuth2Authenticator
class to generate them.
Please cache the OAuth2Credentials
instance as long as the method isExpired
is not true
, to prevent unnecessary
authentication calls.
As the authentication endpoint does not follow the JSON:API protocol, it also throws no JSON:API specific errors or
exceptions. The only relevant errors are variations of the
Dogado\JsonApi\Client\Exception\Oauth2\AuthenticationException
class which differentiates between error message
and code. Such an exception instance also contains the plain response as Psr\Http\Message\ResponseInterface
to have
more context to an error.
Credits
This package contains code taken from enm/json-api-client.
License
The MIT License (MIT). Please see License File for more information.
All versions of json-api-client with dependencies
ext-json Version *
dogado/json-api-common Version ^3.0
psr/http-factory Version ^1.0
psr/http-client Version ^1.0