mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Updating sample for app deploy addpy to include instructions on how to call the REST api.
This commit is contained in:
@@ -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:
|
||||

|
||||
|
||||
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/):
|
||||

|
||||
|
||||
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.
|
||||

|
||||
Next, in the requests body, pass in the parameters to the app you are calling and set the `content-type` to `application/json`:
|
||||

|
||||
When you send the request, you will get the same output as you did when you ran the app through `mssqlctl app run`:
|
||||

|
||||
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 |
Reference in New Issue
Block a user