From dcc563b97a68c097d1764febcea8f0d4049575fd Mon Sep 17 00:00:00 2001 From: Simon Champion Date: Fri, 23 Nov 2018 22:31:42 +0000 Subject: [PATCH] Added examples of API usage. Added example code for using the generated API in the readme. --- readme.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/readme.md b/readme.md index 4f33985..dbe63ee 100644 --- a/readme.md +++ b/readme.md @@ -169,6 +169,35 @@ By default, we use Laravel **Token Based Authentication**, so we need to update
+#### 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]); +
+ + //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. + +
+ ## Config file You can configure your own by publishing the config file: