Updating sample for app deploy addpy to include instructions on how to call the REST api.

This commit is contained in:
Jeroen ter Heerdt
2019-03-08 14:15:12 -08:00
parent ce6626a39c
commit 352b54653b
7 changed files with 52 additions and 1 deletions
@@ -73,7 +73,58 @@ To run this sample, you need the following prerequisites.
"success": true
}
```
6. You can clean up the sample by running the following commands:
6. Any app you create is also accessible using a RESTful web service that is [Swagger](swagger.io) compliant. You can get the endpoint for the web service by running:
```bash
mssqlctl app describe --name addpy --version [version]
```
This will return an output much like the following:
```json
{
"input_param_defs": [
{
"name": "x",
"type": "int"
},
{
"name": "y",
"type": "int"
}
],
"links": {
"app": "https://[IP]:[PORT]/api/app/addpy/[version]",
"swagger": "https://[IP]:[PORT]/api/app/addpy/[version]/swagger.json"
},
"name": "addpy",
"output_param_defs": [
{
"name": "result",
"type": "int"
}
],
"state": "Ready",
"version": "[version]"
}
```
Note the IP address and the port number in this output. Open the following URL in your browser:
`https://[IP]:[PORT]/api/docs/swagger.json`. You will have to log in with the same credentials you used for `mssqlctl login`. The contents of the `swagger.json` you can paste into [Swagger Editor](https://editor.swagger.io) to understand what methods are available:
![API swagger](api_swagger.png)
Notice the `app` GET method as well as the `token` POST method. Since the authentication for apps uses JWT tokens you will need to get a token my using your favorite tool to make a POST call to the `token` method. Here is an example of how to do just that in [Postman](https://www.getpostman.com/):
![Postman Token](postman_token.png)
The result of this request will give you an `access_token`, which you will need to call the URL to run the app.
> *Optional*: If you want, you can open the URL for the `swagger` that was returned when you ran `mssqlctl app describe --name addpy --version [version]` in your browser. You will have to log in with the same credentials you used for `mssqlctl login`. The contents of the `swagger.json` you can paste into [Swagger Editor](https://editor.swagger.io). You will see that the web service exposes the `run` method.
You can use your favorite tool to call the `run` method (`https://[IP]:[PORT]/api/app/addpy/[version]/run`), passing in the parameters in the body of your POST request as json. In this example we will use [Postman](https://www.getpostman.com/). Before making the call, you will need to set the `Authorization` to `Bearer Token` and paste in the token you retrieved earlier. This will set a header on your request. See the screenshot below.
![Postman Run Headers](postman_run_1.png)
Next, in the requests body, pass in the parameters to the app you are calling and set the `content-type` to `application/json`:
![Postman Run Body](postman_run_2.png)
When you send the request, you will get the same output as you did when you ran the app through `mssqlctl app run`:
![Postman Run Result](postman_result.png)
You have now successfully called the app through the web service!
7. You can clean up the sample by running the following commands:
```bash
# delete app
mssqlctl app delete --name addpy --version [version]
Binary file not shown.

After

Width:  |  Height:  |  Size: 104 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB