Skip to content

Commit

Permalink
Added info how to configure the HTTP client
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyholm committed Sep 1, 2016
1 parent 99c9ea0 commit e004e0f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ Cookbook
We have a small cookbook where you can find examples on common use cases:

* [Caching responses](/docs/cookbook/cache.md)
* [Configuring the HTTP client](/docs/cookbook/http-client.md)


Contributing
Expand Down
47 changes: 47 additions & 0 deletions docs/cookbook/http-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Configuring the HTTP client

The Geocoder is decoupled from the HTTP client that sends the HTTP messages. This means
that you are responsible for configuring the HTTP client. Usually the default configuration
is good enough but sometime you may want to do something differently.

How you configure the client differs between different clients below are two examples,
one with [Guzzle6 client](https://github.com/guzzle/guzzle) and one with the
[cURL client](https://github.com/php-http/curl-client).

## Guzzle6

```php
use GuzzleHttp\Client as GuzzleClient;
use Http\Adapter\Guzzle6\Client;
use Geocoder\Provider\GoogleMaps;

$config = [
'timeout' => 2.0,
'verify' => false,
];
$guzzle = new GuzzleClient($config);

$adapter = new Client($guzzle);
$geocoder = new GoogleMaps($adapter);

$geocoder->geocode(...);
```


## cURL

```php
use Http\Client\Curl\Client;
use Geocoder\Provider\GoogleMaps;

$options = [
CURLOPT_CONNECTTIMEOUT => 2,
CURLOPT_SSL_VERIFYPEER => false,
];

$adapter = new Client(null, null, $options);
$geocoder = new GoogleMaps($adapter);

$geocoder->geocode(...);
```

0 comments on commit e004e0f

Please sign in to comment.