Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 0d5337d

Browse files
committed
Sample to create an api revision and switch it to current
1 parent 4a2a575 commit 0d5337d

File tree

4 files changed

+211
-0
lines changed

4 files changed

+211
-0
lines changed

example/api-switch-revision/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
# Create an API Revision and Switch it to Current
3+
4+
This sample creates an Http Bin Api with an Operation, Product and Policy. It creates a revision of the same API, which is not current. The sample then contains a template to switch the newly created revision to current, by creating a release of the Api.
5+
6+
## current
7+
- api-httpbin.current.template.json
8+
9+
Execute this template to create a new `Http Bin` Api having a `GET` Operation and associated to the `Started` Product.
10+
11+
## rev2
12+
- api-httpbin.rev2.template.json
13+
14+
Execute this template to create a copy of the `Http Bin` API having the same `GET` Operation and adds an additional `POST` operation.
15+
16+
## switch
17+
- api-httpbin.switch.template.json
18+
19+
Execute this template to create a `beta` release and switch the `HttpBinApi;rev2` to be the current Api.
20+
21+
**To Execute the template using the script**
22+
23+
```Powershell
24+
$resourceGroupName = "contosoOrganization"
25+
$apimServiceName = "contoso"
26+
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile <templatefilename>.json -ApimServiceName $apimServiceName
27+
```
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"ApimServiceName": {
6+
"type": "string"
7+
}
8+
},
9+
"variables": {},
10+
"resources": [
11+
{
12+
"type": "Microsoft.ApiManagement/service/apis",
13+
"name": "[concat(parameters('ApimServiceName'), '/httpBinAPI')]",
14+
"apiVersion": "2018-01-01",
15+
"properties": {
16+
"displayName": "HTTP Bin API",
17+
"apiRevision": "1",
18+
"description": "API Management facade for a very handy and free online HTTP tool",
19+
"serviceUrl": "https://httpbin.org",
20+
"path": "httpbin",
21+
"protocols": [
22+
"https"
23+
]
24+
}
25+
},
26+
{
27+
"type": "Microsoft.ApiManagement/service/apis/operations",
28+
"name": "[concat(parameters('ApimServiceName'), '/httpBinAPI/get')]",
29+
"apiVersion": "2018-01-01",
30+
"scale": null,
31+
"properties": {
32+
"displayName": "Returns GET data.",
33+
"method": "GET",
34+
"urlTemplate": "/get",
35+
"templateParameters": [],
36+
"description": "Returns GET data.\n",
37+
"responses": [
38+
{
39+
"statusCode": 200,
40+
"description": "OK",
41+
"headers": []
42+
}
43+
]
44+
},
45+
"dependsOn": [
46+
"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), 'httpBinAPI')]"
47+
]
48+
},
49+
{
50+
"type": "Microsoft.ApiManagement/service/products/apis",
51+
"name": "[concat(parameters('ApimServiceName'), '/starter/httpBinAPI')]",
52+
"apiVersion": "2018-01-01",
53+
"scale": null,
54+
"properties": {},
55+
"dependsOn": [
56+
"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), 'httpBinAPI')]"
57+
]
58+
},
59+
{
60+
"type": "Microsoft.ApiManagement/service/apis/policies",
61+
"name": "[concat(parameters('ApimServiceName'), '/httpBinAPI/policy')]",
62+
"apiVersion": "2018-01-01",
63+
"properties": {
64+
"policyContent": "[concat('<!--\r\n IMPORTANT:\r\n - Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements.\r\n - Only the <forward-request> policy element can appear within the <backend> section element.\r\n - To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element.\r\n - To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element.\r\n - To add a policy position the cursor at the desired insertion point and click on the round button associated with the policy.\r\n - To remove a policy, delete the corresponding policy statement from the policy document.\r\n - Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope.\r\n - Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope.\r\n - Policies are applied in the order of their appearance, from the top down.\r\n-->\r\n<policies>\r\n <inbound>\r\n <base />\r\n <set-backend-service base-url=\"https://api.apis.guru/v2/\" />\r\n <rewrite-uri template=\"/metrics.json\" />\r\n </inbound>\r\n <backend>\r\n <base />\r\n </backend>\r\n <outbound>\r\n <base />\r\n </outbound>\r\n <on-error>\r\n <base />\r\n </on-error>\r\n</policies>')]"
65+
},
66+
"dependsOn": [
67+
"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), 'httpBinAPI')]"
68+
]
69+
}
70+
]
71+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"ApimServiceName": {
6+
"type": "string"
7+
}
8+
},
9+
"variables": {},
10+
"resources": [
11+
{
12+
"type": "Microsoft.ApiManagement/service/apis",
13+
"name": "[concat(parameters('ApimServiceName'), '/httpBinAPI;rev=2')]",
14+
"apiVersion": "2018-01-01",
15+
"properties": {
16+
"displayName": "HTTP Bin API",
17+
"description": "API Management facade for a very handy and free online HTTP tool",
18+
"serviceUrl": "https://httpbin.org",
19+
"path": "httpbin",
20+
"protocols": [
21+
"https"
22+
]
23+
}
24+
},
25+
{
26+
"type": "Microsoft.ApiManagement/service/apis/operations",
27+
"name": "[concat(parameters('ApimServiceName'), '/httpBinAPI;rev=2/get')]",
28+
"apiVersion": "2018-01-01",
29+
"scale": null,
30+
"properties": {
31+
"displayName": "Returns GET data.",
32+
"method": "GET",
33+
"urlTemplate": "/get",
34+
"templateParameters": [],
35+
"description": "Returns GET data.\n",
36+
"responses": [
37+
{
38+
"statusCode": 200,
39+
"description": "OK",
40+
"headers": []
41+
}
42+
]
43+
},
44+
"dependsOn": [
45+
"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), 'httpBinAPI;rev=2')]"
46+
]
47+
},
48+
{
49+
"type": "Microsoft.ApiManagement/service/apis/operations",
50+
"name": "[concat(parameters('ApimServiceName'), '/httpBinAPI;rev=2/post')]",
51+
"apiVersion": "2018-01-01",
52+
"scale": null,
53+
"properties": {
54+
"displayName": "Returns POST data.",
55+
"method": "POST",
56+
"urlTemplate": "/post",
57+
"templateParameters": [],
58+
"description": "Returns POST data.\n",
59+
"responses": [
60+
{
61+
"statusCode": 200,
62+
"description": "OK",
63+
"headers": []
64+
}
65+
]
66+
},
67+
"dependsOn": [
68+
"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), 'httpBinAPI;rev=2')]"
69+
]
70+
},
71+
{
72+
"type": "Microsoft.ApiManagement/service/products/apis",
73+
"name": "[concat(parameters('ApimServiceName'), '/starter/httpBinAPI;rev=2')]",
74+
"apiVersion": "2018-01-01",
75+
"scale": null,
76+
"properties": {},
77+
"dependsOn": [
78+
"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), 'httpBinAPI;rev=2')]"
79+
]
80+
},
81+
{
82+
"type": "Microsoft.ApiManagement/service/apis/policies",
83+
"name": "[concat(parameters('ApimServiceName'), '/httpBinAPI;rev=2/policy')]",
84+
"apiVersion": "2018-01-01",
85+
"properties": {
86+
"policyContent": "[concat('<!--\r\n IMPORTANT:\r\n - Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements.\r\n - Only the <forward-request> policy element can appear within the <backend> section element.\r\n - To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element.\r\n - To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element.\r\n - To add a policy position the cursor at the desired insertion point and click on the round button associated with the policy.\r\n - To remove a policy, delete the corresponding policy statement from the policy document.\r\n - Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope.\r\n - Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope.\r\n - Policies are applied in the order of their appearance, from the top down.\r\n-->\r\n<policies>\r\n <inbound>\r\n <base />\r\n <set-backend-service base-url=\"https://api.apis.guru/v2/\" />\r\n <rewrite-uri template=\"/metrics.json\" />\r\n </inbound>\r\n <backend>\r\n <base />\r\n </backend>\r\n <outbound>\r\n <base />\r\n </outbound>\r\n <on-error>\r\n <base />\r\n </on-error>\r\n</policies>')]"
87+
},
88+
"dependsOn": [
89+
"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), 'httpBinAPI;rev=2')]"
90+
]
91+
}
92+
]
93+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"ApimServiceName": {
6+
"type": "string"
7+
}
8+
},
9+
"resources": [
10+
{
11+
"type": "Microsoft.ApiManagement/service/apis/releases",
12+
"name": "[concat(parameters('ApimServiceName'), '/httpBinAPI', '/beta')]",
13+
"apiVersion": "2018-01-01",
14+
"properties": {
15+
"apiId": "[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), 'httpBinAPI;rev=2')]",
16+
"notes": "make revision 2 as current"
17+
}
18+
}
19+
]
20+
}

0 commit comments

Comments
 (0)