2017 © Pedro Peláez
 

joomla-package http

Joomla HTTP Package

image

joomla/http

Joomla HTTP Package

  • Saturday, July 14, 2018
  • by mbabker
  • Repository
  • 10 Watchers
  • 7 Stars
  • 115,248 Installations
  • PHP
  • 16 Dependents
  • 0 Suggesters
  • 14 Forks
  • 1 Open issues
  • 21 Versions
  • 9 % Grown

The README.md

The HTTP Package Build Status

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

The HTTP package includes a suite of classes to facilitate RESTful HTTP requests over a variety of transport protocols., (*2)

The Http\HttpFactory class is used to build the classes required for HTTP requests., (*3)

Interfaces

Http\TransportInterface

Can you help improve this section of the manual?, (*4)

Classes

Http\Http

The Http\Http class provides methods for making RESTful requests., (*5)

Construction

Construction of Http\Http object is generally done using the Http\HttpFactory class. However, Http\Http is not abstract and can be instantiated directly passing an optional array of options and an optional Http\TransportInterface object. If the transport is omitted, the default transport will be used. The default is determined by looking up the transports folder and selecting the first transport that is supported (this will usually be the "curl" transport)., (*6)

use Joomla\Http\Http;
use Joomla\Http\Transport\Stream as StreamTransport;

$options = array();

$transport = new StreamTransport($options);

// Create a 'stream' transport.
$http = new Http($options, $transport);
Making a HEAD request

An HTTP HEAD request can be made using the head method passing a URL and an optional key-value array of header variables. The method will return a Http\Response object., (*7)

use Joomla\Http\HttpFactory;

// Create an instance of a default Http object.
$http = Http\HttpFactory::getHttp();

// Invoke the HEAD request.
$response = $http->head('http://example.com');

// The response code is included in the "code" property.
// See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
var_dump($response->code);

// The response headers are included as an associative array in the "headers" property.
var_dump($response->headers);

// The body of the response (not applicable for the HEAD method) is included in the "body" property.
var_dump($response->body);
Making a GET request

An HTTP GET request can be made using the get method passing a URL, an optional key-value array of header variables and an optional timeout value. In RESTful terms, a GET request is sent to read data from the server., (*8)

// Invoke the GET request.
$response = $http->get('http://api.example.com/cars');
Making a POST request

An HTTP POST request can be made using the post method passing a URL, a data variable, an optional key-value array of header variables and an optional timeout value. The data can be either an associative array of POST variables, or a string to be sent with the request. In RESTful terms, a POST request is sent to create new data on the server., (*9)

// Prepare the update data.
$data = array('make' => 'Holden', model => 'EJ-Special');

// Invoke the GET request.
$response = $http->post('http://api.example.com/cars/1', $data);
Making a PUT request

An HTTP POST request can be made using the post method passing a URL, a data variable, an optional key-value array of header variables and an optional timeout value. The data can be either an associative array of POST variables, or a string to be sent with the request. In RESTful terms, a PUT request is typically sent to update existing data on the server., (*10)

// Prepare the update data.
$data = array('description' => 'My first car.', 'color' => 'gray');

// Invoke the GET request.
$response = $http->put('http://api.example.com/cars/1', $data);
Making a DELETE request

An HTTP DELETE request can be made using the delete method passing a URL, an optional key-value array of header variables and an optional timeout value. In RESTful terms, a DELETE request is typically sent to delete existing data on the server., (*11)

// Invoke the DELETE request.
$response = $http->delete('http://api.example.com/cars/1');
Making a TRACE request

An HTTP TRACE request can be made using the trace method passing a URL and an optional key-value array of header variables. In RESTful terms, a TRACE request is to echo data back to the client for debugging or testing purposes., (*12)

Working with options

Customs headers can be pased into each REST request, but they can also be set globally in the constructor options where the option path starts with "headers.". In the case where a request method passes additional headers, those will override the headers set in the options., (*13)


// Configure a custom Accept header for all requests. $options = array( 'headers.Accept' => 'application/vnd.github.html+json' ); // Make the request, knowing the custom Accept header will be used. $pull = $http->get('https://api.github.com/repos/joomla/joomla-platform/pulls/1'); // Set up custom headers for a single request. $headers = array('Accept' => 'application/foo'); // In this case, the Accept header in $headers will override the options header. $pull = $http->get('https://api.github.com/repos/joomla/joomla-platform/pulls/1', $headers);

Http\HttpFactory

Http\Http objects are created by using the Http\HttpFactory::getHttp method., (*14)

// The default transport will be 'curl' because this is the first transport.
$http = Http\HttpFactory::getHttp();

// Create a 'stream' transport.
$http = Http\HttpFactory::getHttp(null, 'stream');

Joomla\Http\Response

Can you help improve this section of the manual?, (*15)

Joomla\Http\Transport\Curl

Can you help improve this section of the manual?, (*16)

Joomla\Http\Transport\Socket

Can you help improve this section of the manual?, (*17)

Joomla\Http\Transport\Stream

Can you help improve this section of the manual?, (*18)

Installation via Composer

Add "joomla/http": "~1.0" to the require block in your composer.json and then run composer install., (*19)

{
    "require": {
        "joomla/http": "~1.0"
    }
}

Alternatively, you can simply run the following from the command line:, (*20)

composer require joomla/http "~1.0"

If you want to include the test sources, use, (*21)

composer require --prefer-source joomla/http "~1.0"

The Versions

30/06 2018

dev-master

9999999-dev https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+ GPL-2.0-or-later

The Requires

 

The Development Requires

framework http joomla

23/04 2018

1.3.2

1.3.2.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

framework http joomla

13/03 2018

1.3.1

1.3.1.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0-or-later

The Requires

 

The Development Requires

framework http joomla

26/09 2016

1.3.0

1.3.0.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

01/03 2016

1.2.2

1.2.2.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

17/12 2015

1.2.1

1.2.1.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

19/09 2015

1.2.0

1.2.0.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

03/05 2015

1.1.7

1.1.7.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

05/03 2015

1.1.6

1.1.6.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

16/12 2014

1.1.5

1.1.5.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

23/08 2014

1.1.4

1.1.4.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

25/03 2014

1.1.2

1.1.2.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

25/03 2014

1.1.3

1.1.3.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

10/02 2014

1.1.1

1.1.1.0 https://github.com/joomla-framework/http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

The Development Requires

framework http joomla

05/11 2013

1.0

1.0.0.0 https://github.com/joomla/joomla-framework-http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

framework http joomla

05/11 2013

1.1.0

1.1.0.0 https://github.com/joomla/joomla-framework-http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

framework http joomla

22/10 2013

1.0-beta3

1.0.0.0-beta3 https://github.com/joomla/joomla-framework-http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

framework http joomla

16/08 2013

1.0-beta2

1.0.0.0-beta2 https://github.com/joomla/joomla-framework-http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

framework http joomla

16/08 2013

1.0-beta

1.0.0.0-beta https://github.com/joomla/joomla-framework-http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

framework http joomla

04/06 2013

1.0-alpha

1.0.0.0-alpha https://github.com/joomla/joomla-framework-http

Joomla HTTP Package

  Sources   Download

GPL-2.0+

The Requires

 

framework http joomla