2017 © Pedro Peláez
 

library http

Small library for get/post requests

image

sfadless/http

Small library for get/post requests

  • Wednesday, February 14, 2018
  • by sfadless
  • Repository
  • 1 Watchers
  • 0 Stars
  • 30 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 3 % Grown

The README.md

HTTP small library for get/post requests

Documentation

Instalation

composer require Sfadless/http

Usage

Basic usage

use Sfadless\Utils\Http\Http;

require_once __DIR__ . '/vendor/autoload.php';

$http = new Http();

$response = $http->get('http://some.url');
$response = $http->post('http://some.url');

Usage with params and headers

use Sfadless\Utils\Http\Http;

require_once __DIR__ . '/vendor/autoload.php';

$http = new Http();

$params = [
    'param1' => 'value',
    'param2' => 'value2'
];

$headers = [
    'header1' => 'value',
    'header2' => 'value'
];

$response = $http->post('http://some.url', $params, $headers);

Request and response formats

By default, response value is string and request value is array. If your service always return specific format (for example - json), you may pass those formats in constructor, (*1)

use Sfadless\Utils\Http\Http;
use Sfadless\Utils\Http\Format\Request\ArrayRequestFormat;
use Sfadless\Utils\Http\Format\Response\JsonResponseFormat;

$http = new Http(
    new ArrayRequestFormat(), //instanse of RequestFormatInterface, used by default
    new JsonResponseFormat(), //instanse of ResponseFormatInterface, response value will be passed throught getFormattedResponse method
);

You may create your own formats for request and response by implementing RequestFormatInterface and ResponseFormatInterface. In request, you should create formatParams() method, in which will be passed $params (second argument for ->post() and ->get() methods), and return value for stream context option. For response format, you should implement getFormattedResponse() method, this is the layer between response from server and you code., (*2)

The Versions

14/02 2018

dev-master

9999999-dev

Small library for get/post requests

  Sources   Download

The Requires

  • php >=5.4

 

14/02 2018

2.0

2.0.0.0

Small library for get/post requests

  Sources   Download

The Requires

  • php >=5.4

 

13/02 2018

1.2.x-dev

1.2.9999999.9999999-dev

Small library for get/post requests

  Sources   Download

The Requires

 

02/02 2018

1.2

1.2.0.0

Small library for get/post requests

  Sources   Download

The Requires

  • php >=5.4

 

01/02 2018

1.1.1

1.1.1.0

Make http get/post requests

  Sources   Download

The Requires

  • php >=5.4

 

01/02 2018

1.1

1.1.0.0

Make http get/post requests

  Sources   Download

The Requires

  • php >=5.4

 

21/09 2017

1.0

1.0.0.0

Make http get/post requests

  Sources   Download

The Requires

  • php ^5.4 || >=7.0.8

 

21/09 2017

1.1.x-dev

1.1.9999999.9999999-dev

Make http get/post requests

  Sources   Download

The Requires

  • php ^5.4 || >=7.0.8