PHP code example of jpdik / request

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

    

jpdik / request example snippets


$req = new Request("https://api.openweathermap.org/data/2.5");

$res = $req->get("/weather", "?q=São joão del rei&appid=d15abc236092bbf9dd28fa2c0a7a02a9");

$status = res->getStatusCode();

if($status == 200 && $res){
  echo json_encode($res);
}

//GET
get($url, $option = null, array $headers = null, $timeout = null)

//POST
post($url, $body, $option = null, array $headers = null, $timeout = null)

//PUT
put($url, $body, $option = null, array $headers = null, $timeout = null)

//DELETE
delete($url, $option = null, array $headers = null, $timeout = null)

//Get the status from request
getStatusCode()

$headers = [
  "Content-Type: application/json",
  "Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ0b2tlbiI6IjcyYTg0NDdhOTA3MGYyZTVmOGIzZDkzYzViZjE4MWE0In0.99kTzhSVwges69qprisg9B3rty4eKTTBurH-1lGKe30"];

$headers = [
  "Content-Type: application/json",
];

$req = new Request("https://api.openweathermap.org/data/2.5");

$res = $req->get("/weather", "?q=São joão del rei&appid=d15abc236092bbf9dd28fa2c0a7a02a9");

$status = res->getStatusCode();

if($status == 200 && $res){
  echo json_encode($res);
}