Can Azure Operate Substitute Internet API?

Just a few days in the past, I successfully migrated an ASP.NET Core Internet API undertaking to  Azure Operate, thereby getting the good thing about the serverless features of the Azure platform to reduce operation and maintenance bills, which made it 10 instances simpler. This text will introduce the necessary steps and practices inside the migration method that can enable you to perceive the Migration ideas.

Why the Serverless – Azure perform?

Azure Features is a serverless compute service and easy answer for operating small items of code, or “features,” inside the cloud. It might make our growth much more productive. You will write simply the code you’ll for the matter at hand, with out concern of the entire software or the infrastructure to run it.

Code Distinction

Lastly, on the factor that .NET programmers are most concerned with, what’s the distinction between the perform code and the unique Internet API code? To begin with, you do not want Program.cs anymore, Startup.cs, Controller is gone too, appsettings.json is gone too, now it is simply your online business code. Now my app layer has just one class, the logic is similar to the unique net API controller.

HTTP Set off Operate == Internet API Motion

// ASP.NET Internet API
// Endpoint URL: /merchandise/{id}
public async Process<IActionResult> GetProduct(int id)
  // Deal with HTTP Request Headers

  // Deal with HTTP Request Message

  // Return HTTP Response
  var msg = new { Id = id, Message = "Hi there World" };
  return Okay(msg);

// Azure Features HTTP Set off
// Endpoint URL: /api/merchandise/{id}
public static async Process<HttpResponseMessage> Run(HttpRequestMessage req, int id, TraceWriter log)
  // Deal with HTTP Request Headers

  // Deal with HTTP Request Message

  // Return HTTP Response
  var msg = new { Id = id, Message = "Hi there World" };
  return req.CreateResponse(HttpStatusCode.OK, msg);

There are some main variations we must always know earlier than migration:

Azure Features are at all times static strategies

Regardless that Azure Features are extensions of Azure WebJobs, each attribute has a static modifier with the help of utilizing design, in distinction to Azure WebJobs perhaps with out the static modifier.
Actions of Internet API, with the help of utilizing the way in which, don’t have the static modifier. This end result in a good-sized architectural extrade in the course of the migration, particularly with dependency injection (DI). We are going to contact it later.

Azure Features at all times acquire the HttpRequestMessage instance as a parameter

Throughout the HTTP request/response pipeline, a Internet API controller internally creates an HttpContext instance to cope with info like headers, cookies, periods, question strings, and request body (of path question strings and request body could also be handled in a one in every of a form manner). The HttpContext instance works as an inside asset so any movement can immediately get right of entry to it. Consequently, each movement passes important information as its parameters.

On the opposite hand, each attribute takes a one-of-a-kind HTTP request/response pipeline from Internet API, which passes the HttpRequestMessage instance to the attribute as a parameter. The HttpRequestMessage instance finest handles headers, question strings, and request frames. It doesn’t seem after cookies or periods. That is the large distinction between Internet API and Azure Features in phrases of stateless.

Features ought to think about service locator patterns for dependency administration

There are lots of acceptable IoC discipline libraries for Internet API to manage dependencies. Nonetheless, we have already talked about in my previous submit, Managing Dependencies in Azure Features, that Service Locator Sample needs to be considered for DI in Azure Features, and in reality, that’s the handiest method to deal with dependencies for now. That is as a result of reality every Azure Operate has a static modifier which prevents us from the utilization of the an identical method as the one in Internet API. We understand particular critiques in direction of provider locator kinds for Azure Features exist on the market, nonetheless that’s past our subject, so we’re in a position to discuss it later in another submit.

For reference – The right way to use Dependency injection and Crud Operations utilizing Azure Operate with .Internet Core, Do examine my one other article right here


Migrating from a easy net API that has little industrial strain to Azure Operate can save important growth and operational prices. By utilizing the serverless platform, we will give attention to the enterprise logic itself slightly than the infrastructure code. We will proceed to make use of the programming language we all know whereas sustaining some flexibility and safety.

Thanks for studying, please let me know your questions, ideas, or suggestions within the feedback part. I respect your suggestions and encouragement.

Continue learning!!!

Show More

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button