2017 © Pedro PelĂĄez
 

library php-network

Network - A lightweight library to send HTTP requests

image

valmaraz/php-network

Network - A lightweight library to send HTTP requests

  • Saturday, January 28, 2017
  • by vAlmaraz
  • Repository
  • 1 Watchers
  • 1 Stars
  • 8 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Network

Packagist Packagist Packagist, (*1)

Network is a lightweight library to send http requests., (*2)

Installation

composer require vAlmaraz/php-network

Usage

use vAlmaraz\network\Network;

// Set URL and execute request
$response = Network::get($url)->execute();

// Retrieve response
echo $response->getBody();

Advanced Usage

use vAlmaraz\network\Network;

$timeoutInSeconds = 3;
$headers = ['Accept' => 'application/json'];
$formData = ['field1' => 'value1', 'field2' => 'value2'];

// Configure request
$response = Network::post($url)
    ->setTimeoutInSeconds($timeoutInSeconds)
    ->withHeaders($headers)
    ->withFormData($formData)
    ->execute();

// Retrieve response info
echo $response->getStatusCode();
echo json_encode($response->getHeaders());
echo $response->getBody();

Examples

use vAlmaraz\network\Network;

$network = new Network();
// GET
$response = $network->get('https://jsonplaceholder.typicode.com/posts')
    ->execute();
// POST
$response = $network->post('https://jsonplaceholder.typicode.com/posts')
    ->withFormData(['title' => 'My title', 'body' => 'The body', 'userId' => 123])
    ->execute();
// PATCH
$response = $network->patch('https://jsonplaceholder.typicode.com/posts/1')
    ->withFormData(['title' => 'A new title'])
    ->execute();
// PUT
$response = $network->put('https://jsonplaceholder.typicode.com/posts/1')
    ->withFormData(['title' => 'My title', 'body' => 'The body', 'userId' => 123])
    ->execute();
// DELETE
$response = $network->delete('https://jsonplaceholder.typicode.com/posts/1')
    ->execute();

echo 'Status code: ' . $response->getStatusCode() . PHP_EOL . PHP_EOL;
echo 'Headers: ' . json_encode($response->getHeaders()) . PHP_EOL . PHP_EOL;
echo 'Body: ' . $response->getBody();

License

This project is licensed under the MIT license. Please see the LICENSE file for more information., (*3)

The Versions

28/01 2017

dev-master

9999999-dev https://github.com/vAlmaraz/php-network

Network - A lightweight library to send HTTP requests

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

by VĂ­ctor Almaraz

curl http request network

28/01 2017

dev-develop

dev-develop https://github.com/vAlmaraz/php-network

Network - A lightweight library to send HTTP requests

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

by VĂ­ctor Almaraz

curl http request network

28/01 2017

v0.0.2

0.0.2.0 https://github.com/vAlmaraz/php-network

Network - A lightweight library to send HTTP requests

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

by VĂ­ctor Almaraz

curl http request network

28/01 2017

v0.0.1

0.0.1.0 https://github.com/vAlmaraz/php-network

Network - A lightweight library for performing HTTP requests

  Sources   Download

MIT

The Requires

  • php >= 5.4

 

by VĂ­ctor Almaraz

curl http request network