Download the PHP package hussainweb/drupal-api-client without Composer
On this page you can find all versions of the php package hussainweb/drupal-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hussainweb/drupal-api-client
More information about hussainweb/drupal-api-client
Files in hussainweb/drupal-api-client
Package drupal-api-client
Short Description Convenient wrapper on Guzzle to access Drupal.org API
License GPL-2.0-or-later
Informations about the package drupal-api-client
Drupal.org API client
This is a simple wrapper on Guzzle 6 to access and use the API provided by drupal.org. It was built for DruStats which was built for a developer contest in DrupalCon Asia. You can refer to DruStats for example usage.
Installation
Use composer to install the package.
Drupal API client version 2+ no longer depends on Guzzle. It can work with any HTTP client that implements a HTTPlug compatible ClientInterface. Here's a list of providers.
For example, to use Guzzle, you would need the Guzzle 6 adapter. This will install Guzzle 6 as well.
Usage
The library provides a single client and multiple request classes to send requests to drupal.org API. To send a request, create a request object and call the getEntity
method on the client class.
The above example uses Guzzle 6 Adapter but any HTTP client implementing php-http based clients will work. Construct the HTTP client and pass it when constructing the Hussainweb\DrupalApi\Client
class.
There are various request classes to retrieve different types of entities and entity listings. Many of the entity request classes have a corresponding list request class as well, e.g. CommentRequest
and CommentCollectionRequest
.
User Agent
In accordance with responsible usage of Drupal.org API, it is important to set the user-agent header to indicate your application. You may set this request once globally using the static property on the Request
class.
Request::$userAgent = 'Drupal Statistics Collector';
You have to do this only once as this user-agent is applied to all child requests as well. See the test in \Hussainweb\DrupalApi\Tests\Request\RequestTest::testRequestUserAgent
for verifying the behaviour.
Note on HTTP client implementations
As noted above, Drupal API Client version 2+ no longer depends on Guzzle but any HTTP client which provides a php-http/client-implementation. This is a PSR-18 compatible HTTP client interface and you can read more about it at HTTPlug.
Since PSR-18 has been implemented in a different provider (psr/http-client-implementation), this client might move to that in the near future. Right now, almost all clients that support the HTTPlug interface also supports the PSR-18 interface and you would be able to use that client right now. The only notable exception is Guzzle 7 but there is discussion to add support for that in an adapter.
All versions of drupal-api-client with dependencies
ext-json Version *
guzzlehttp/psr7 Version ^1.6 || ^2.4
php-http/client-implementation Version ^1.0
psr/http-client Version ^1.0
psr/http-message Version ^1.0 || ^2.0