PHP-HTTP/HTTPlug client for Drupal 7
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
spec/Http/Client/Drupal7
src
.editorconfig
.gitignore
.php_cs.dist
.travis.yml
README.md
composer.json
grumphp.yml.dist
phpspec.yml.dist

README.md

Build Status

Drupal 7 HTTP Client

This is a small experimental library to bridge HTTPlug and Drupal 7.

The function sending requests in Drupal 7 is drupal_http_request(). The return of it is not PSR-7 compatible.

This library standardize this and allows you to send HTTP requests and get HTTP responses in PSR-7 standard by using Drupal 7 API.

Installation

composer require drupol\drupal7_http_client

Usage

A GET request:

  $client = new \Http\Client\Drupal7\Client();
  $message = new \Http\Message\Drupal7\MessageFactory();

  $request = $message->createRequest('GET', 'http://google.com/');
  $response = $client->sendRequest($request);

A POST request:

  $uri = 'http://google.com/';
  $data = array(
    'body' => 'Lorem Ipsum Dolor Sit Amet',
  );

  $client = new \Http\Client\Drupal7\Client();
  $message = new \Http\Message\Drupal7\MessageFactory();

  $request = $message->createRequest('POST', $uri, array(), drupal_http_build_query($data));
  $response = $client->sendRequest($request);