Browse Source

Merge pull request #11 from Spudley/master

Added examples of API usage.
tags/1.2.9
Nafies Luthfi 7 years ago
committed by GitHub
parent
commit
48e45d3747
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 29
      readme.md

29
readme.md

@ -169,6 +169,35 @@ By default, we use Laravel **Token Based Authentication**, so we need to update
<br>
#### API Usage
The generated API is a REST API, using GET and POST verbs, with a URI of `/api/modelname`.
Example code for calling the generated API, using Guzzle:
//Read data a specific Vehicle record...
$uri = 'http://your-domain.com/api/vehicles/'.$vehicleID;
$headers = ['Authorization' => 'Bearer '.$apiToken];
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', $uri, ['headers' => $headers]);
<br>
//Create a new Vehicle record...
$uri = 'http://your-domain.com/api/vehicles';
$headers = ['Authorization' => 'Bearer '.$apiToken];
$payload = json_encode([
'name' => 'Vehicle Name 1',
'description' => 'Vehicle Description 1',
]);
$client = new \GuzzleHttp\Client();
$res = $client->request('POST', $uri, ['body' => $payload, 'headers' => $headers]);
The generated functional tests will give you examples of how to adapt this code for other call types.
<br>
## Config file
You can configure your own by publishing the config file:

Loading…
Cancel
Save