Skip to content

Latest commit

 

History

History
53 lines (45 loc) · 2.02 KB

PARAMETERS.md

File metadata and controls

53 lines (45 loc) · 2.02 KB

Parameters

Client configuration parameters

Here is the list of parameters you can set when defining e new HttpClient

Name Type Description Required
responsefactory ResponseFactoryInterface Response factory YES
requestfactory RequestFactoryInterface Request factory YES
urifactory UriFactoryInterface Uri factory YES
headers array Associative array with default headers
baseuri string|UriInterface Base uri for requests
useragent string Client's User-Agent
followlocation bool Follow HTTP 3xx redirect (Default: false)
maxredirects integer The maximum amount of HTTP redirections to follow (default: 0)
timeout integer Connection timeout in seconds (Default: php.ini's default_socket_timeout)

Example

$config = [
    'requestfactory'  => new Http\Factory\Diactoros\RequestFactory,
    'responsefactory' => new Http\Factory\Diactoros\ResponseFactory,
    'urifactory'      => new Http\Factory\Diactoros\UriFactory,
    'baseuri'         => 'http://api.example.com',
    'timeout'         => 30,
    'headers'         => [
        'Content-Type' => 'application/json'
    ]
];

$client = Sfn\HttpClient\ClientFactory::make($config);

Request parameters

Here is the list of parameters you can set when sending a request via REST methods.

Name Type Description
headers array Associative array with request headers
body string Request body

Example

$options = [
    'body'    => json_encode($post_fields),
    'headers' => [
        'Content-Type' => 'application/json'
    ]
];

$response = $client->post('http://api.example.com/path', $options);