Use Visual Studio to develop, test and deploy Azure Functions (a) Development

1. What is Azure functions

       Azure Functions are Microsoft Azure PaaS provides a fully managed service for server-free architecture. Azure Functions is a fully scalable, flexible, reliable and safe service. Also known as non-server applications, Azure Functions

Triggered by an event, rather than a call directly from the application. You can specify the type of event that will trigger function application function .

       To put it plainly can use the "Azure Functions" to host your code without having to create a virtual machine, and lists the language Azure Function can use C #, Java, JavaScript, PowerShell, Python or "Azure Functions" support in any language write Function. And to create a "Azure Function", Azure provide us with a number of templates. E.g

  . 1, HTTPTrigger : HTTP request occurs when the Web application, HTTP runs the trigger function

  2, TimerTrigger : Use this event to run Azure Functions between the general field according to the plan that you define.

  3, BlobTrigger : When you upload or modify files in Azure Blob storage, will run this function type

  4, CosmosDBTrigger : when a document is added to the Azure Cosmos DB database or in which the modification, this trigger runs.

  .......

  Do not do too much description here today focused on the presentation "HttpTrigger" type "Azure Functions" function.

       Visual Studio provides an excellent environment for creating and testing Azure Functions application. Before deploying to cloud the Azure Functions available in local development Azure Functions and verify that it works correctly. Today, we are creating a HTTPTrigger of Azure Functions application, by definition, is Dangdang HTTPTrigger Web application occurs when the HTTP request, HTTP trigger will run the function. It may also be used in response to this trigger Webhook. Webhook is called back occurred when modifying the term web hosting. For example, you can create a Azure Functions, when the term repository is changed, the function will be triggered GitHub repository Webhook. .

1, create Azure Functions application (I use here is VS2019)

(1) New projects in the template search box, enter "Azure", select "Azure Functions" project templates for creating Azure Functions.

 Note: If no template Azure Functions Use Visual Studio Installer to check the "Azure development support" for

 

(2) new Azure Functions program should, then you can see VS provides a variety of triggers, here we choose "Http the Trigger"
  (2.1) the Authorization Level, we select the "Anonymous"

       (2.2) AzureWebJobStorage, select "Storage Simulator"

 Once created, we will re-generation project,

(3) Add "Azure function" on "Azure.Protal.Functions" project, select "Http trigger", modify the Authorization level to "Anonymous" named "WatchPortalFunction" function

       After writing the trace log statements, add the following code to the body of the method. This code reads the query string from the URL of the HTTP request  model parameters. The code then retrieve the details of this monitoring model; In this example, the function returns the number of dummy data only. Finally, the function returns a response to these details. If no initial request comprising a  model query string parameter, this function will return an error message.

 

 1             string model = req.Query["model"];
 2 
 3             // If the user specified a model id, find the details of the model of watch
 4             if (model != null)
 5             {
 6                 // Use dummy data for this example
 7                 dynamic watchinfo = new 
 8                          { 
 9                                Manufacturer = "Abc", 
10                                CaseType = "Solid",     
11                                Bezel = "Titanium", 
12                                Dial = "Roman", 
13                                CaseFinish = "Silver", 
14                                Jewels = 15 
15                         };
16 
17                 return (ActionResult)new OkObjectResult($"Watch Details: {watchinfo.Manufacturer}, {watchinfo.CaseType}, {watchinfo.Bezel}, {watchinfo.Dial}, {watchinfo.CaseFinish}, {watchinfo.Jewels}");
18             }
19             return new BadRequestObjectResult("Please provide a watch model in the query string");       

 

 

In the local test Azure Functions

(1) Click "Start Debugging." At this point Visual Studio to generate "Azure Functions" application and "Azure Functions" run at startup.

 

 

 

 When run ready, HTTP list of functions available, and it can be used to trigger the URL for each function.

 

 

(2) testing inside the browser

       Open a Web browser and enter the URL "http://localhost:7071/api/WatchPortalFunction?model=abd"。

       This request triggers "WatchPortalFunction" function, and the model  abc is passed as a query string parameter. For more information about virtual return "Azure Functions" generated.

 

 

(3) tested in the Postman

       Post time using Postman issue request, pass parameters "QueryString" manner.

 At this point, I can see in the local development "Azure Functions" of "Http Tirgger" type function successfully up and running locally, completed the first step in getting started "Azure Functions".

Third, the summary

This chapter is a problem for me before I met at work, taking advantage of the holiday to consider a solution, although only a small problem, but still quite reference, if we can give you a little in the daily development help, honored.

Source: https: //www.cnblogs.com/AllenMaster/articles/12633088.html

Author: Allen

Copyright: reproduced in the article clearly indicate the position of the author and source. If mistakes are found, welcome criticism.

 

Third, the summary

This chapter is a problem for me before I met at work, taking advantage of the holiday to consider a solution, although only a small problem, but still quite reference, if we can give you a little in the daily development help, honored.

Guess you like

Origin www.cnblogs.com/AllenMaster/p/12633088.html