Skip to content

Commit 352b546

Browse files
Updating sample for app deploy addpy to include instructions on how to call the REST api.
1 parent ce6626a commit 352b546

7 files changed

Lines changed: 52 additions & 1 deletion

File tree

samples/features/sql-big-data-cluster/app-deploy/addpy/README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,58 @@ To run this sample, you need the following prerequisites.
7373
"success": true
7474
}
7575
```
76-
6. You can clean up the sample by running the following commands:
76+
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:
77+
```bash
78+
mssqlctl app describe --name addpy --version [version]
79+
```
80+
This will return an output much like the following:
81+
```json
82+
{
83+
"input_param_defs": [
84+
{
85+
"name": "x",
86+
"type": "int"
87+
},
88+
{
89+
"name": "y",
90+
"type": "int"
91+
}
92+
],
93+
"links": {
94+
"app": "https://[IP]:[PORT]/api/app/addpy/[version]",
95+
"swagger": "https://[IP]:[PORT]/api/app/addpy/[version]/swagger.json"
96+
},
97+
"name": "addpy",
98+
"output_param_defs": [
99+
{
100+
"name": "result",
101+
"type": "int"
102+
}
103+
],
104+
"state": "Ready",
105+
"version": "[version]"
106+
}
107+
```
108+
Note the IP address and the port number in this output. Open the following URL in your browser:
109+
`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:
110+
![API swagger](api_swagger.png)
111+
112+
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/):
113+
![Postman Token](postman_token.png)
114+
115+
The result of this request will give you an `access_token`, which you will need to call the URL to run the app.
116+
117+
> *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.
118+
119+
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.
120+
![Postman Run Headers](postman_run_1.png)
121+
Next, in the requests body, pass in the parameters to the app you are calling and set the `content-type` to `application/json`:
122+
![Postman Run Body](postman_run_2.png)
123+
When you send the request, you will get the same output as you did when you ran the app through `mssqlctl app run`:
124+
![Postman Run Result](postman_result.png)
125+
You have now successfully called the app through the web service!
126+
127+
7. You can clean up the sample by running the following commands:
77128
```bash
78129
# delete app
79130
mssqlctl app delete --name addpy --version [version]
104 KB
Loading
120 KB
Loading
13.7 KB
Loading
15.1 KB
Loading
13.9 KB
Loading
16.3 KB
Loading

0 commit comments

Comments
 (0)