PHP code example of bernardosilva / jwt-api-client-php
1. Go to this page and download the library: Download bernardosilva/jwt-api-client-php 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/ */
bernardosilva / jwt-api-client-php example snippets
use BernardoSilva\JWTAPIClient\APIClient;
use BernardoSilva\JWTAPIClient\AccessTokenCredentials;
$username = 'your-username';
$password = 'your-password';
$baseURI = 'api.your-domain.pt';
$client = new APIClient($baseURI);
$options = [
'verify' => false, // might need this if API uses self signed certificate
'form_params' => [
'key' => $username,
'password' => $password
]
];
// authenticate on API to get token
$response = $client->post('/api/v1/auth/login', $options);
$loginResponseDecoded = json_decode($response->getBody()->getContents(), true);
$credentials = new AccessTokenCredentials($loginResponseDecoded['access_token']);
$client->setCredentials($credentials);
// e.g. Request types
$client->get();
$client->delete();
$client->patch();
$client->post();
$client->put();
$ composer