Azure Functions Create Function in VS Code - microsoft-campus-community/workshop-shopping-list-bot GitHub Wiki

Prerequisite: This page assumes that you have a fork of this repository and are on the workshop branch. You will also need Visual Studio Code with Azure Functions Extension installed.

On this page, you will create a new Azure Function with an HTTP trigger that should implement the REST endpoint to add an item to a shopping list. Open the functions folder of the workshop branch in Visual Studio Code.

  1. In Visual Studio Code, open the Azure Extension in the left toolbar.
  2. Expand the 'Functions' tab and click on the 'lightning bolt with the little green +' icon to create a new Function. Screenshot of Visual Studio Code with Function tab in Azure extension panel expanded and red circle around 'Create Function' button.
  3. As a template for the Azure Function, select HTTP trigger. Screenshot of Visual Studio Code with 'Select a template for your function' prompt and red arrow pointing to 'HTTP trigger' in the list of templates.
  4. When prompted, type AddItemFunction into the name text box. Screenshot of Visual Studio Code prompt to enter the name for the Function to create with 'AddItemFunction' typed into the text box.
  5. For 'Authorization Level', select Anonymous. This has nothing to do with individual users' authorization, which we do not touch in this workshop. The authorization level of an Azure Functions configures whether a client needs to present a key when calling the Function. Screenshot of Visual Studio Code Function creation process prompt for 'Authorization Level' and a red pointer pointing to 'Anonymous' in the list of available authorization levels.

Now you have a basic template to write the Function to add an item to a shopping list.

Overview what gets generated

Now that you have a new Azure Function from the HTTP template, let's look at what got generated for you.

  1. Open the functions/AddItemFunction folder in your IDE.
  2. The first file is function.json, which contains a specific configuration for this single Function. For example, that this Function is an HTTP trigger. Azure Functions can be triggered by many other events than just a simple HTTP request.
  3. index.ts contains the actual code for your Function. By default, it generates a basic 'Hello World' example.
  4. You can delete the sample.dat file. It only contains example data the 'Hello World' code can get as input in the HTTP request body.

In the next part, you will write the code for this Function.

NEXT: Implement AddItem Azure Function