Search by

hussainweb / drupal-api-client

hussainweb

Convenient wrapper on Guzzle to access Drupal.org API

Package info

github.com/hussainweb/drupal-api-client

pkg:composer/hussainweb/drupal-api-client

Statistics

Installs: 8 970

Dependents: 0

Suggesters: 0

Stars: 14

Open Issues: 1

v2.3.0 2026-10-23 01:53 UTC

README

Latest Version Software License Build Status Total Downloads

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.