PHP code example of thenextinvoice / norest
1. Go to this page and download the library: Download thenextinvoice/norest 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/ */
thenextinvoice / norest example snippets
$client = new \TheNextInvoice\NoREST\Client('https://api.example.com')
->setContentType('text/plain')
->addHeader('X-Sent-By', 'James Bond');
try {
$secret_endpoint = $client->get('/endpoint/secret');
$response = $client->post($secret_endpoint, $my_secret_stuff);
} catch (\TheNextInvoice\NoREST\Exceptions\RequestFailedException $e) {
echo 'oops, request failed: ' . $e->getMessage() . PHP_EOL;
echo 'the response body was' . PHP_EOL;
echo $e->getBody();
}
echo 'server response was:' . PHP_EOL
echo $response . PHP_EOL;
$client = new \TheNextInvoice\NoREST\Client('https//api.example.com')
->addHeader('X-CaSeInSeNsItIvEiSsTuPiD', 'true', ['nolowercase' => true]);
// this won't work
$client->post('/endpoint');
// but this will
$client->post('/endpoint', []);
// Construct client with JSON flags
$client = new \TheNextInvoice\NoREST\Client('https//api.example.com', [], [JSON_UNESCAPED_SLASHES, JSON_HEX_TAG]);