PHP code example of brieucthomas / ergast-client

1. Go to this page and download the library: Download brieucthomas/ergast-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/ */

    

brieucthomas / ergast-client example snippets


use BrieucThomas\ErgastClient\ErgastClientBuilder;
use BrieucThomas\ErgastClient\Request\RequestBuilder;

$ergastClient = ErgastClientBuilder::createErgastClient();

$requestBuilder = new RequestBuilder();
$requestBuilder
    ->findCircuits()
    ->byId('monza')
;

$response = $ergastClient->execute($requestBuilder->build());
$circuit = $response->getCircuits()->first();

echo $circuit->getId();                       // "monza"
echo $circuit->getName();                     // "Autodromo Nazionale di Monza"
echo $circuit->getUrl();                      // "http://en.wikipedia.org/wiki/Autodromo_Nazionale_Monza"
echo $circuit->getLocation()->getLocality();  // "Monza"
echo $circuit->getLocation()->getCountry();   // "Italy"
echo $circuit->getLocation()->getLatitude();  // 45.6156
echo $circuit->getLocation()->getLongitude(); // 9.28111

$uriBuilder
    ->setFirstResult(2)
    ->setMaxResults(5)
;