https://github.com/drupol/drupal7_http_client
PHP-HTTP/HTTPlug client for Drupal 7
https://github.com/drupol/drupal7_http_client
Last synced: 8 months ago
JSON representation
PHP-HTTP/HTTPlug client for Drupal 7
- Host: GitHub
- URL: https://github.com/drupol/drupal7_http_client
- Owner: drupol
- Archived: true
- Created: 2017-10-24T20:42:29.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-03T20:48:13.000Z (over 8 years ago)
- Last Synced: 2024-12-17T09:23:58.088Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://travis-ci.org/drupol/drupal7_http_client)
# Drupal 7 HTTP Client
This is a small experimental library to bridge [HTTPlug](https://github.com/php-http/httplug) and Drupal 7.
The function sending requests in Drupal 7 is [drupal_http_request()](https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_http_request/7.x).
The return of it is not [PSR-7](http://www.php-fig.org/psr/psr-7/) compatible.
This library standardize this and allows you to send HTTP requests and get HTTP responses in [PSR-7 standard](http://www.php-fig.org/psr/psr-7/) by using Drupal 7 API.
## Installation
```php
composer require drupol\drupal7_http_client
```
## Usage
A **GET** request:
```php
$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:
```php
$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);
```