Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce API version 1.0 #254

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/AzureIoTHub.Portal/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ public static async Task Main(string[] args)
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");

builder.Services.AddHttpClient("api", client => client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress))
/*.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>()*/;
builder.Services.AddHttpClient("api", client =>
{
client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress);
client.DefaultRequestHeaders.Add("X-Version", "1.0");
})
/*.AddHttpMessageHandler<BaseAddressAuthorizationMessageHandler>()*/;

builder.Services.AddFileReaderService(o => o.UseWasmSharedBuffer = true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace AzureIoTHub.Portal.Server.Controllers
using Microsoft.AspNetCore.Mvc;

[ApiController]
[ApiVersion("1.0")]
[Route("api/models/{modelId}/commands")]
[ApiExplorerSettings(GroupName = "Device Models")]
public class DeviceModelCommandsController : ControllerBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace AzureIoTHub.Portal.Server.Controllers
using Microsoft.AspNetCore.Mvc;

[ApiController]
[ApiVersion("1.0")]
[Route("api/models")]
[ApiExplorerSettings(GroupName = "Device Models")]
public class DeviceModelsController : ControllerBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace AzureIoTHub.Portal.Server.Controllers
using Microsoft.Extensions.Logging;

[ApiController]
[ApiVersion("1.0")]
[Route("api/devices")]
[ApiExplorerSettings(GroupName = "IoT Devices")]
public class DevicesController : ControllerBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace AzureIoTHub.Portal.Server.Controllers
using Newtonsoft.Json.Linq;

[ApiController]
[ApiVersion("1.0")]
[Route("api/edge/configurations")]
[ApiExplorerSettings(GroupName = "IoT Edge")]
public class EdgeConfigurationsController : ControllerBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace AzureIoTHub.Portal.Server.Controllers
using Newtonsoft.Json.Linq;

[ApiController]
[ApiVersion("1.0")]
[Route("api/edge/device")]
[ApiExplorerSettings(GroupName = "IoT Edge")]
public class EdgeDevicesController : ControllerBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace AzureIoTHub.Portal.Server.Controllers
using Microsoft.Extensions.Logging;

[ApiController]
[ApiVersion("1.0")]
[Route("api/lorawan/concentrators")]
[ApiExplorerSettings(GroupName = "LoRa WAN")]
public class LoRaWANConcentratorsController : ControllerBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace AzureIoTHub.Portal.Server.Controllers

[ApiController]
[AllowAnonymous]
[ApiVersion("1.0")]
[Route("/api/settings")]
[Produces("application/json")]
[ApiExplorerSettings(GroupName = "Portal Settings")]
Expand Down
12 changes: 12 additions & 0 deletions src/AzureIoTHub.Portal/Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace AzureIoTHub.Portal.Server
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Azure.Devices;
using Microsoft.Azure.Devices.Provisioning.Service;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -146,6 +148,16 @@ public void ConfigureServices(IServiceCollection services)
opts.TagActionsBy(api => new[] { api.GroupName });
opts.DocInclusionPredicate((name, api) => true);
});

services.AddApiVersioning(o =>
{
o.AssumeDefaultVersionWhenUnspecified = true;
o.DefaultApiVersion = new ApiVersion(1, 0);
o.ReportApiVersions = true;
o.ApiVersionReader = ApiVersionReader.Combine(
new QueryStringApiVersionReader("api-version"),
new HeaderApiVersionReader("X-Version"));
});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down