Skip to content

Instantly share code, notes, and snippets.

@KamranSyed
Last active April 24, 2018 04:45
Show Gist options
  • Select an option

  • Save KamranSyed/3dfa229b81e3a93f3e608f35f88f0495 to your computer and use it in GitHub Desktop.

Select an option

Save KamranSyed/3dfa229b81e3a93f3e608f35f88f0495 to your computer and use it in GitHub Desktop.
Php REST Client (Weather) Learning by Example
<?php
//This is part of a youtube video tutorial at https://youtu.be/gFg3BlQUJ0E
//include the rest client lib
//PHP REST Client https://github.com/KamranSyed/php-restclient
require_once 'restclient.php';
$url = "http://api.openweathermap.org/data/2.5/";
$api = new RestClient([
'base_url' => $url,
'format' => "json"
]);
//Cities list of IDs can be downloaded from http://bulk.openweathermap.org/sample/city.list.json.gz
//Shows current weather
$result = $api->get("weather?id=1176615&units=metric&appid=0bcc8438b0a075420b98e5087317cbd5");
//Following line shows 5 days forecast
//$result = $api->get("forecast?id=1176615&units=metric&appid=0bcc8438b0a075420b98e5087317cbd5");
echo "<pre>";
if($result->info->http_code == 200){
print_r($result->decode_response());
}else{
print_r($result);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment