I´m looking into host our web API in Azure using an API app. I am using the Azure API Manager in front of the API App to expose the developer portal to some of our consumers. The web API is built in .NET core and it has version support using the URL (https://example.com/api/v2/controller...). I have given it swagger support and one swagger.json is created for each version. These swagger files I use in my ARM templates to set up API Manager and expose this versioned API. When adding a version to API Manager I have to give a path which must be unique for the API Im adding. So for version v1 I give "api/v1" and for v2 I give "api/v2". So far so good. The problem is when trying to call the API using API Manager the URL ends up to be: https://foo-api-manager-dev.azure-api.net/api/v2/api/v2/tests So the "api/v2"-part i duplicated. I guess it has something to do with how API Manager works and how my versioning is set up in my web API. When calling the controllers directly to the API App then the URL is correct.
I have searched around a lot and tried different approaches to this but could really need some input here. All suggestions are appreciated!
My routing is managed in a base controller and looks like this
[Produces("application/json")]
[Route("api/v{version:apiVersion}/[controller]")]
public abstract class VersionBaseController : ApiController
{
protected VersionBaseController()
: base()
{
}
}
Controllers like this:
[ApiVersion("2.0")]
public class TestsController : VersionBaseController
{
[HttpGet]
public string Get()
{
return "Get works V2";
}
The entire template to create the api manager:
//Create API Manager
{
"apiVersion": "2018-06-01-preview",
"name": "[parameters('apim_name')]",
"location": "[parameters('location')]",
"type": "Microsoft.ApiManagement/service",
"sku": {
"name": "[parameters('apim_tier')]",
"capacity": 1
},
"properties": {
"publisherEmail": "[parameters('apim_adminEmail')]",
"publisherName": "[parameters('apim_orgName')]"
},
"resources": [
//Create version set
{
"apiVersion": "2017-03-01",
"type": "Microsoft.ApiManagement/service/api-version-sets",
"name": "[concat(parameters('apim_name'), '/', parameters('VersionSetName'))]",
"dependsOn": [
"[concat('Microsoft.ApiManagement/service/', parameters('apim_name'))]"
],
"properties": {
"description": "Version configuration",
"displayName": "Api set 1",
"versioningScheme": "Segment"
}
},
//Link version 1
{
"apiVersion": "2017-03-01",
"type": "apis",
"name": "AvidaAPIV1",
"dependsOn": [
"[resourceId('Microsoft.ApiManagement/service/api-version-sets', parameters('apim_name'), parameters('VersionSetName'))]",
"[concat('Microsoft.ApiManagement/service/', parameters('apim_name'))]"
],
"properties": {
"contentFormat": "swagger-link-json",
"contentValue": "[concat(parameters('ExternalApiBaseUrl'),'/swagger/v1/swagger.json')]",
"path": "/api/v1",
"isCurrent": true,
"apiVersion": "v1",
"apiVersionName": "v1",
"apiVersionDescription": "string",
"apiVersionSetId": "[concat('Microsoft.ApiManagement/service/api-version-sets', parameters('VersionSetName'))]"
}
},
//Link version 2
{
"apiVersion": "2017-03-01",
"type": "apis",
"name": "AvidaAPIV2",
"dependsOn": [
"[resourceId('Microsoft.ApiManagement/service/api-version-sets', parameters('apim_name'), parameters('VersionSetName'))]",
"[concat('Microsoft.ApiManagement/service/', parameters('apim_name'))]"
],
"properties": {
"contentFormat": "swagger-link-json",
"contentValue": "[concat(parameters('ExternalApiBaseUrl'),'/swagger/v2/swagger.json')]",
"path": "/api/v2",
"isCurrent": false,
"apiVersion": "v2",
"apiVersionName": "v2",
"apiVersionDescription": "string",
"apiVersionSetId": "[concat('Microsoft.ApiManagement/service/api-version-sets', parameters('VersionSetName'))]"
}
},
//Create unlimited product
{
"apiVersion": "2017-03-01",
"type": "products",
"name": "[concat('UnlimitedProduct', parameters('ProductNameSuffix'))]",
"dependsOn": [
"[concat('Microsoft.ApiManagement/service/', parameters('apim_name'))]"
],
"properties": {
"displayName": "[concat('UnlimitedProduct', parameters('ProductNameSuffix'))]",
"description": "Unlimited external access",
"terms": "",
"subscriptionRequired": false,
"state": "published"
},
"resources": [
{
"apiVersion": "2017-03-01",
"type": "apis",
"name": "AvidaAPIV1",
"dependsOn": [
"[concat('Microsoft.ApiManagement/service/', parameters('apim_name'))]",
"[concat('Microsoft.ApiManagement/service/', parameters('apim_name'), '/apis/AvidaAPIV1')]",
//"[concat('Microsoft.ApiManagement/service/', parameters('apim_name'), '/apis/AvidaAPIV2')]",
"[concat('Microsoft.ApiManagement/service/', parameters('apim_name'), '/products/UnlimitedProduct', parameters('ProductNameSuffix'))]"
]
}
]
}