Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

PHP client #11

Open
karussell opened this issue Aug 7, 2015 · 1 comment
Open

PHP client #11

karussell opened this issue Aug 7, 2015 · 1 comment

Comments

@karussell
Copy link
Member

We got a request asking for how to do an API request via PHP. The most important part is to use the correct URL:

<?
$adr='https://graphhopper.com/api/1/geocode?q=' . urlencode('Deutschland Berlin') . '&locale=de&key=[YOUR_KEY]';
$str=file_get_contents($adr);
echo $str;
?>

Or for the routing API:

<?
$adr='https://graphhopper.com/api/1/route?point=' . lat1 . ',' . lon1 . '&point=' . lat2 . ',' . lon2 . '&locale=de&vehicle=car&key=[YOUR_KEY]';
$str=file_get_contents($adr);
echo $str;
?>

Then use the $str for further JSON parsing or use httpful a HTTP client making such requests easy for PHP.

Our route optimization API contains a swagger specification from which you can easily create an already working PHP client. Contact us if you do not know how to handle that.

@karussell karussell changed the title PHP requesting PHP client Aug 7, 2015
@webdevilopers
Copy link

For anyone using @guzzle and @symfony Components:

use Symfony\Component\Serializer\Encoder\JsonDecode;
use Symfony\Component\Serializer\Encoder\JsonEncoder;

$client = new \GuzzleHttp\Client();
$response = $client->request('GET', $uri);

$decoder = new JsonDecode();
$routing = $decoder->decode($response->getBody()->getContents(), JsonEncoder::FORMAT);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants