Exercise - Create an HTTP trigger

In this unit, we're going to create an Azure function that accepts an HTTP request with a single string. The function returns a string back to the caller to represent success or failure. We'll continue working on the function from the previous exercise.

Create an HTTP trigger

Let's continue using our existing Azure Functions application and add an HTTP trigger.

  1. Make sure you are signed into the Azure portal using the same account you activated the sandbox with.

  2. On the Azure portal menu or from the Home page, select All resources.

  3. Select your function app. Your Function App page appears.

  4. In the left nav bar, under the Functions section, select Functions. The Functions page for your function app appears.

  5. On the menu bar, select + Add. This action starts the function creation process. The Add function panel appears.

  6. In the Select a template section, select HTTP trigger.

  7. In the Template details section, in New Function text box, enter a name for the function. In the Authorization level dropdown, select Anonymous, and then select Add.

  8. Take a quick look at the auto-generated code to get an idea about what's going on. The req parameter represents the incoming request and contains a name parameter. We check to see if name has a value. If it does, we return a greeting. Otherwise, we return an error message.

  1. Make sure you are signed into the Azure portal using the same account you activated the sandbox with.

  2. On the Azure portal menu or from the Home page, select All resources.

  3. Select your function app. Your Function App page appears.

  4. In the left nav bar, under the Functions section, select Functions. The Functions page for your function app appears.

  5. In the Select a template section, select HTTP trigger.

  6. In the Template details section, in New Function text box, enter a name for the function. In the Authorization level dropdown, select Anonymous, and then select Add.

  7. Take a quick look at the auto-generated code to get an idea about what's going on. The $Request parameter represents the incoming request and contains a name parameter. We check to see if name has a value. If it does, we use Push-OutputBinding to write a greeting to the response. Otherwise, we write an error message to the response.

Get your function URL

Now that we've created the HTTP trigger, let's get the function URL so we can begin to make a request.

  1. To the right of Delete, select Get Function Url. The Get Function Url dialog appears.

  2. Select Copy (clipboard), and select OK to close the function URL dialog.

Issue a GET request to your HTTP trigger

We now have our function URL copied to our clipboard. Let's issue a GET request to see if we get a response.

  1. Open a new tab in your web browser.

  2. Paste the URL into the address bar.

  3. Add a query string parameter called name with your name for example .../api/HttpTriggerCSharp1?name=Jesse

  4. Press Enter to submit the request.

  1. Open a new tab in your web browser.

  2. Paste the URL into the address bar.

  3. Add a query string parameter called name with your name for example .../api/HttpTriggerCSharp1?name=Jesse

  4. Press Enter to submit the request.