Skip to content

Latest commit

 

History

History
53 lines (43 loc) · 1.01 KB

README.md

File metadata and controls

53 lines (43 loc) · 1.01 KB

php-http-request

Modular, Object oriented CURL wrapper

Usage

$response = $http->url('http://localhost')
    ->body(array('a' => 'aa'))
    ->setContentType('application/json')
    ->POST();
$body = $response->json();

You can use the following http methods:

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE
  • OPTIONS
  • HEAD

This package provides the multicurl process

// create 3 requests
$multiOpener = $http->createCurlGroup();

$multiOpener->url('http://localhost')
    ->GET();
$multiOpener->url('http://localhost')
    ->body(array('pippo' => 1))
    ->POST();
$multiOpener->url('http://localhost')
    ->body(array('pippo' => 1))
    ->setContentType('application/json')
    ->PUT();

// execute the requests return an array with all responses
$responses = $http->execute($multiOpener);

foreach ($responses as $response) {
    var_dump($response->json());
}

Or you can use the shortcut:

$response = HTTP::get('http://localhost', array('key' => 1));
var_dump($response->body());