UgenTec.Framework.Core.WebApi
UgenTec.Framework.Core.WebApi
is a library package containing helper classes for usage in WebApis.
Installation
Use the internal Ugentec Nuget-2 feed to install the UgenTec.Framework.Core.WebApi library
install-package UgenTec.Framework.Core.WebApi
Usage
Application Version Check middleware
UgenTec.Framework.Core.WebApi contains asp.net core middleware to verify if the version clients of webapi's matches with the expectancy of the webapi itself. Typical usecase would be for private apis, in which client and server code are tightly coupled, since backward compatibility is not a consideration when moving private apis forward. Another use case are SDKs for public services. Using this middleware we can prohibit older versions (or newer versions) of SDKs calling into web apis.
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseApplicationVersionCheck("1.0.0", "UT-Application-Version");
}
}
If the version passed in the UT-Application-Version header does not match with the server expectancy, an ApplicationVersionMismatch
exception is thrown.
Request Compression middleware
UgenTec.Framework.Core.WebApi contains asp.net core middleware for dealing with compressed requests.
asp.net core typically only deals with response compression, so this middleware is used to decode compressed request information.
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseRequestCompression();
}
}
The middleware will inspect the 'Content-Encoding' header and perform decompression of the request accordingly.
Exception mapping
UgenTec.Framework.Core.WebApi contains a helper method for configuring an asp.net core exceptionhandler which maps exceptions occuring during the execution of request into http responses with a specific status code and/or body.
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseExceptionHandler(new ExceptionHandlerOptions()
{
ExceptionHandler =
new ExceptionHandlingBuilder()
.MapException<ArgumentOutOfRangeException>(e =>
(StatusCodes.Status400BadRequest,
new ErrorDetails() { Message = e.Message }));
.Build()
});
}
}
Identity flow middleware
UgenTec.Framework.Core.WebApi contains asp.net core middleware for capturing user name, tenant id and tenant shortcode information passed through http-headers by http clients that are configured to relay that information.
This middleware only executes on authenticated calls, where the original user is a non-human client.
The distinction is based on the claims that IdentityServer passes by default in case of human login vs machine login.
In concrete if as sub
claim is present, the authenticated user is considered a human actor and identity flow will not happen.
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
app.UseIdentityFlow();
}
}