1. Go to this page and download the library: Download ebski/http-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ebski / http-client example snippets
use Ebski\HttpClient\HttpClient;
use Ebski\HttpClient\HttpClientConfiguration;
use Ebski\HttpClient\HttpRequest;
use GuzzleHttp\Psr7\Response;
class TidesAndCurrentsClient extends HttpClient
{
public function __construct()
{
parent::__construct(new HttpClientConfiguration('https://api.tidesandcurrents.noaa.gov'));
}
protected function configureUrl(string $endpoint) : string
{
return '/api/prod/datagetter' . ltrim($endpoint, '/');
}
protected function handleResponse(Response $response)
{
$code = $response->getStatusCode();
if ($code === 200) {
return json_decode($response->getBody(), true);
}
// Handle exception properly
throw new Exception();
}
}
class Test
{
public function testFunction()
{
$client = new TidesAndCurrentsClient();
$queryParams = [
'begin_date' => '20130808 15:00',
'end_date' => '20130808 15:06',
'station' => 8454000,
'product' => 'water_temperature',
'units' => 'english',
'time_zone' => 'gmt',
'application' => 'ports_screen',
'format' => 'json',
];
$request = new HttpRequest('GET', '', $queryParams);
$response = $client->request($request);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.