Scroll down to the Request body text box, change the value of the make property to “ Chevrolet”, and click Run. When the function runs, this value is used to filter the data to return.
In the Develop tab, review the Code window and notice that this C# code expects an HTTP request with a “make” value (car make) passed either in the message body or in a query string. Since the Azure Functions contain functional code, you can immediately test your new function. Step 3 – Test the Azure function in Azure’s portal You should have something like the following: Return req.CreateResponse(HttpStatusCode.OK, enumerableListOfVehicles) IEnumerable enumerableListOfVehicles = requestedVehicles Var requestedVehicles = from vehicle in listOfVehicles Return req.CreateResponse(HttpStatusCode.BadRequest, “Please pass a car make (make param, like make=Chevrolet) on the query string or in the request body”) FirstOrDefault(q => string.Compare(q.Key, “make”, true) = 0)ĭynamic data = await () String make = req.GetQueryNameValuePairs() Log.Info($”C# HTTP trigger function processed a request. Public static async Task Run(HttpRequestMessage req, TraceWriter log) You can simply copy/paste the following code into your function if you want to go faster: In this simple case, for simplicity’s sake, I’m generating the data (a List,Vehicle>) within my code and using Linq. Of course, in a real case, your function code might be accesing some kind of data source like Azure SQL DB, DocDB, Azure Storage, etc. Step 2 – Write the code for your Azure Function in the web editor
This creates a function that is based on the specified template. In your function app, click + New Function > HttpTrigger – C#, provide a name for the Function and hit “Create”. At this point you have your Azure Function App environment where you can create as many Functions as you’d like. To create a new function app, type a unique Name for your new function app or accept the generated one, select your preferred Region, then click Create + get started. If you have an existing function app to use, select it from Your function apps then click Open. Go to the Azure portal and sign-in with your Azure account.
If you don’t already have an Azure account, free accounts are available or even better, free benefits with VS Dev Essentials (Azure credit, $25/month for 12 months, for free). Before you can create a function, you need to have an active Azure subscription account. Step 1 – Create the Azure Function app environment in Azure’s portalĪ “function app” hosts the execution of your functions in Azure.
You can get an Overview of Azure Functions here, and more details about how to implement Azure Functions with. You can write just the code you need for the problem at hand, without worrying about a whole application or the infrastructure to run it.” “ Azure Functions is a solution for easily running small pieces of code, or ‘functions’ in the cloud. With Azure Functions you can create event-driven task/services with a server-less approach, just like publishing a C# function in the cloud and, ‘voila’, it’ll work right away! It is a convenient way to create small web services that you can invoke through HTTP, they can also be scheduled or triggered by events.
With Xamarin.Forms you can create native cross-platform mobile apps with C#, targeting iOS, Android and UWP. But I think this E2E walkthrough is interesting in any case if you are not aware of Azure Functions and/or Xamarin.Forms. Make no mistake about it, you consume an Azure Function from a Xamarin app in the same way you’d consume a regular web service or ASP.NET Web API deployed in Azure in any other environment (Azure App Service or even Azure Service Fabric). I was testing Azure Functions by creating a simple proof of concept with a Xamarin.Forms client and since there’s not much info about “using Azure Functions from Xamarin” I thought it was a good idea to publish this Getting Started or Walkthrough in my MSDN blog.