4
votes

I have created azure functions with "HTTP trigger" and "generic Webhooks" with Visual studio 2017.The only difference I found that both "triggers" can be triggered by HTTP request.

both functions have "HttpTrigger" as parameter. so I am confused when should we use one over the other as both triggers allows us to run small piece of code in cloud.

How Is it different from one another ?

3

3 Answers

4
votes

An HttpTriggered function can respond to any HTTP verb you configure. However, a webhook only responds to POST and expects the payload to be JSON.

Source: https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook#responding-to-webhooks

This restricts requests to only those using HTTP POST and with the application/json content type.

2
votes

A 'Webhook' is a user defined callback that can be registered on a website in case you want to react to certain events.

For example something that is often done is responding to events in a gtihub repository, like when someone does a check-in or an issue is added. Typically you would want to trigger a build when a check-in happens. You can register a callback/webhook on github which points to a url provided by you that reacts to the HTTP POST called by github.

Azure function can be configured to be triggered by a normal HTTP request or it can be setup as a webhook i.e. it will be called whenever a specific event on some website has occurred. Functions configured as webhooks will respond only to a HTTP POST. There are already built in values to set up an Azure Function as a github or Slack webhook.

If you are not reacting to an external event or cannot register a webhook in the event source just go with the HttpTrigger and explicitly invoke your function.

1
votes

As per the documentation, the webhooks only work with 1.x version of Azure functions runtime while if you are working with the newer runtime 2.x - it is recommended to use the HttpTrigger instead.

From the documentation,

In version 1.x, webhook templates provide additional validation for webhook payloads. In version 2.x, the base HTTP trigger still works and is the recommended approach for webhooks.