Skip to main content

Posts

Showing posts from April, 2020

Versioning an API

Strategies 1. URI Each time we change the version, the clients will have to change the URL. 2. Via Query String 3. Via Headers The client needs to have a developer who knows how to deal with headers, more sophisticated approach. Also we need to create our own custom header. 4.  VIA ACCEPT HEADERS Add  the nuget package -- Microsoft.AspNetCore.Mvc.Versioning [ApiVersion("1.0")] [ApiVersion("1.1")] [ApiVersion("2.0")] public class WeatherForecastController : ControllerBase Add this to the controller to let the user know what version it supports. To the actions Specify these.         [HttpGet("sample")]         [MapToApiVersion("1.0")]         public IActionResult Getv1(string id) => Ok("Version 1");         [HttpGet("sample")]         [MapToApiVersion("1.1")]         public IActionResult Getv2() => Ok("Version ...

Custom Authorization Attribute with dependency injection

Custom Authorization attribute with Dependency resolved using HttpContext. FOR SYNCHRONOUS    public class CustomAuthFilter : AuthorizeAttribute, IAuthorizationFilter     {         public CustomAuthFilter(params string[] args)         {             Args = args;         }         public string[] Args { get; }         public void OnAuthorization(AuthorizationFilterContext context)         {             int x = this.Args.Length;             var service = context.HttpContext.RequestServices.GetRequiredService<ISample>();             string name = service.GetName();             context.Result = new UnauthorizedResult();         }     } Contr...

Azure Functions

Azure App Service also supports the concept of web jobs. Web jobs offer a simple way to get your own background tasks, such as key processing, deployed to the same service in your hosting plan that are running the web application. So what we have with web applications and web jobs is a very programmer-friendly model that makes it super easy to create and deploy multiple websites along with background processing tasks and bundle them all up onto one server to keep your costs down, but with the flexibility to scale up as the demands of your application require. Azure Functions is actually built on top of the web jobs SDK and it's hosted on the App Service platform. So in many ways you can think of it as just another part of this same offering, but with a few additional powerful new capabilities  Azure Functions is the idea of events and code. You simply supply some code, which is just a single function usually written either in C# or JavaScript, and you tell Azure Functions what ...