drupol/drupal7_http_client

0.1.0 2017-12-03 20:49 UTC

README

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);