Download the PHP package edmundluong/php-api-client without Composer
On this page you can find all versions of the php package edmundluong/php-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download edmundluong/php-api-client
More information about edmundluong/php-api-client
Files in edmundluong/php-api-client
Package php-api-client
Short Description Provides a simple layer of abstraction over Guzzle Services
License MIT
Informations about the package php-api-client
PHP API Client
Provides a simple layer of abstraction over the Guzzle Services client in order to facilitate common tasks related to making API requests to web services, such as logging and HTTP request signing for authentication purposes.
Installation
PHP API Client requires PHP 5.5 or higher. Install the package via Composer:
Basic Usage
Define the API endpoints you want to access by extending the AbstractApiDescription
base class
and overriding the load()
method to return a new static
with the API endpoints defined.
[See documentation on Guzzle Service Descriptions for more information.] (http://guzzle3.readthedocs.org/webservice-client/guzzle-service-descriptions.html)
An example of a Twitter URLs API description:
To consume your API description with an API client, simply extend the AbstractApiClient
base class and override the
$apiDescription
field with your API description's class name:
Finally, instantiate your API client and make API calls using the method names you defined in the API description,
under the operations
section:
Response:
Authenticators
Should you need authentication for your API requests, you can authenticate your client with an Authenticator
object.
Authenticator
objects intercept outgoing HTTP requests and sign them before they are sent out.
This is very useful for various authentication flows, such as OAuth2 or HMAC, where requests must have additional parameters appended to them (e.g., access tokens).
Simply extend the AbstractAuthenticator
base class and define the authentication logic required
within the sign()
method:
In this example, TwitterUrlsOauthAuthenticator
appends access_token=token_value
to all GET requests.
In order to authenticate the client using the Authenticator
, simply override the $authenticators
array
field from AbstractApiClient
with an associative array of Authenticator
class names:
The key value that the Authenticator
class name is mapped to (in this case, 'oauth2'
) is used to locate the desired
Authenticator
object for the client during initialization. Simply pass authType
in your configuration array with the
desired key to apply the Authenticator
object to your client:
Debugging
The AbstractApiClient
base class has a built-in LogSubscriber
that can be toggled on/off
by passing in a debug
flag in the configuration array for the client (note that the value must be true
):
Using the OAuth2 client from the previous example:
Output:
Additionally, a PSR-3 compatible Logger can be passed into the configuration array as well for usage
by passing in a debugLogger
option:
Documentation
See the official Guzzle Web Service client documentation for more information.
Contributing
Please submit any pull requests to the develop
branch.
Pull requests are welcome and will be happily accepted given that the contributed code follows the PSR-2 Coding Style Guide.
License
For the full copyright and license information, please view the LICENSE file that was distributed with this source code.
All versions of php-api-client with dependencies
guzzlehttp/guzzle-services Version 0.5
guzzlehttp/log-subscriber Version ~1.0