HTTP trigger

The HTTP trigger is normally used to create the API or services, where we request for data using the HTTP protocol and get the response. We can also integrate the HTTP trigger with a Webhook.

Let's start creating the HTTP trigger. We have already created a simple Azure Function and trigger. Now we will create the HTTP Login API. In this, we will send the login credential through an HTTP post request and get the response as to whether the user is valid or not.

Since we have already created a Function app in the previous example, we can now add multiple functions to it.

  1. Click on + |, select HttpTrigger-JavaScript, provide the function name, and click on the Create button:
  1. After we click on the Create button, the default template will be available. Now, we can edit and test the function:
  1. Now edit the code as follows:
  1. Save and run the code, as shown in the following screenshot:
  1. The login service is ready. Now let's check this service in Postman.
  2. To get the URL from the function, click on Get function URL:
  1. We will use Postman to check our service. Postman is a Chrome extension for API developers to test APIs. To add the Chrome extension, go to Settings in Chrome and select More tools | Extensions, as shown in the following screenshot:
  1. Click on Get more extensions:
  1. Now search for postman and then click on + ADD TO CHROME:
  1. Click on Add app:
  1. Launch the Postman app. Click on Sign Up with Google:
  1. The Postman window will look like this:

Once the initial setup is done, test the API.

  1. Copy the function URL and paste it in Postman. Select the method type POST and provide a request body and click on the Send button:
>
  1. If we provide the correct username and password in the request body, we will get the response, user is valid; otherwise, the response will be invalid user.

In the next section, we will discuss event hubs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.70.38