hussainweb / drupal-api-client
Convenient wrapper on Guzzle to access Drupal.org API
Requires
- php: >=8.2
- ext-json: *
- guzzlehttp/psr7: ^1.6 || ^2.4 || ^3.0
- psr/http-client: ^1.0
- psr/http-client-implementation: ^1.0
- psr/http-message: ^1.0 || ^2.0
Requires (Dev)
- php-http/mock-client: ^1.3
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^9.0
- rector/rector: ^0.18.3
- squizlabs/php_codesniffer: ^3.5 || ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-23 01:54:47 UTC
README
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.
composer require hussainweb/drupal-api-client:"^2.0"
Drupal API client version 2+ does not depend on a specific HTTP client. It works with any PSR-18 HTTP client. Here's a list of providers.
For example, Guzzle 7 and later implement PSR-18 directly, so you can pass a GuzzleHttp\Client without any adapter.
composer require guzzlehttp/guzzle
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.
use GuzzleHttp\Client as GuzzleClient; use Hussainweb\DrupalApi\Client; use Hussainweb\DrupalApi\Request\UserRequest; $http_client = new GuzzleClient(['timeout' => 2]); // Retrieve user with uid 314031. $client = new Client($http_client); $user_request = new UserRequest('314031'); $user = $client->getEntity($user_request);
Any PSR-18 HTTP client will work. Construct the HTTP client and pass it when constructing the Hussainweb\DrupalApi\Client class.
Note on HTTP client implementations
Version 2.3 and later require any psr/http-client-implementation. Earlier 2.x versions required php-http/client-implementation (HTTPlug), which blocked Guzzle 8 and Drupal 12, so a Guzzle adapter is no longer needed.