What is a WebHook in Azure - azure

Can anybody explain at a very basic level what a webhook is in azure. Also how do webhooks differ from azure functions and webjobs in azure

There isn't any service available in Azure called "webhook". A webhook is simply an addressable HTTP endpoint that allows external applications to communicate with your system. You could implement webhooks using a variety of Azure services such as Azure Functions, a web app running an API, etc.

This is a bit of a late answer but it may help someone.
In Azure you can use webhooks to trigger an Azure function see Microsoft Functions Documentation

A webhook in azure is an HTTP endpoint. It is a user defined address you can call with relevant information to interact with several other services. Think of it as a sort of mailbox that you can configure services to respond to. You send an HTTP request (mail a letter) and it lands in this mailbox and you have configured say... Azure functions to respond to that particular mailbox or … logic apps or … data factory … The last one for example. You can have data factory post to a webhook when its completed its work if you need some follow on function to be notified upon job complete.
These are different from functions or webjobs in that they do not have any programable logic to execute a task or job. Webhooks are a customizable location to which you can post HTTP requests.

In some main services of Azure like the Container Registry, webhooks are actually listed as a Service within this Service.
Container Registry on the webhook page
With the Container Registry, for example, you can set up a webhook to send out information if there is a new version of a container image available.
The receiving end of the webhook would then be for example the App Service. Here the information can be used to trigger a build of the web app with the updated container image. This example is super easy to setup, because the sending and receiving end are both within Azure. You use the “Continuous Deployment” option within the Container settings of your web app.
Azure Web App page on container settings
When the sending end would be a repository outside of Azure, then the setup is a bit more complicated. If you are interested, check out the learn doc on that:
https://learn.microsoft.com/en-us/learn/modules/deploy-run-container-app-service/6-update-web-app
So in general terms, a webhook is a method to send and receive information from one Service to another. With that you can trigger events or control other functionality. The “web” part means it uses HTTP to transmit the information and the “hook” part means, that you can connect one or more services like that together inside or outside of Azure.

Azure Functions are more or less a highly specialized version of a WebJob built on Azure WebJobs SDK. Webhooks allow you to trigger webjobs and azure functions with an http call.

I'm very late to answer this but in Azure, you can specify a webhook URL to do something when (for example) a shutdown is triggered. You can webhook to email, SMS, alert users, run basic functions, send an APNS to your iOS device, or GCM to an android device.
If you put a URL for your webhook API you effectively send:
A notification will post to the specified webhook endpoint when
the auto-shutdown is about to happen. The endpoint must support
incoming TLS 1.2 connections.
You can also create a Webhook Azure Consumer in Visual Studio. This link has some information stepping you through it: https://www.sparkpost.com/blog/azure-functions/.
Here is a simple code for an Azure Function App (M$ template):
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string name = req.Query["name"];
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
dynamic data = JsonConvert.DeserializeObject(requestBody);
name = name ?? data?.name;
string responseMessage = string.IsNullOrEmpty(name)
? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
: $"Hello, {name}. This HTTP triggered function executed successfully.";
return new OkObjectResult(responseMessage);
}
}
}

API - Always has one answer and interaction (Post, Get...)
A <=====> B
Webhook- is a trigger to run something.
A --------> B
API vs Webhook
Webhook Anatomy in Azure
URL - The address containing a security token used to call the
Runbook.
Request Header - A hash table containing the header information
for the webhook.
Request Body - Data passed to the runbook. The data can be a string,
JSON or XML. The runbook must be able to consume the data type sent
in the webhook.
Webhook Name - The name of the webhook is passed to the runbook.

A Hook by definition is trying to get hold of information from the middle of sequence of flow or process. By the same definition webhook is a type of hook that supports https protocol that infrastructure provider has to support. Azure Webhooks are Https endpoints which can be of two type internal to azure or external to azure. By internal I mean azure function or azure logic apps can be created as a webhook(a https endpoint using trigger connectors), external means you create custom endpoint which which understands the post request send by the azure resource.
Webhook is be used as an alerting or custom processing mechanism to trigger something elsewhere to enable reporting or follow up action.
For example events supported by Microsoft such oncreating ondeleting are all hooks by they are of type native clrhooks

Related

HTTPS endpoint of Azure event hub

I am using service that can only send messages using webhook. The only thing I can set up in that webhook are HTTP endpoint, user name and password (you can see it on the screenshot below). I would like to send messages to my event hub, but I don't know how to find its HTTP endpoint. The only thing I could find was SAS Endpoint.
Event Hubs offers a REST API that allows you to perform a subset of the operations supported by its AMQP API. Publishing basic events via REST is possible and would use the endpoint: https://{servicebusNamespace}.servicebus.windows.net/{eventHubPath}/messages.
The full set of documentation for the REST API can be found here, and the specifics for sending events here.

How to store and get http form data in Azure Insights for Azure Function app

We have Azure Function app (v.4) with post api calls to some external rest resource. I can see occasional failures in Azure monitoring (Azure Insights), but everything I was able to collect in Logs is external api endpoint url (Path like https://... when you open dependencies) with the request get parameters. In order to troubelshoot the failure I need to collect Form data as well for post requests. I wonder how easy it would be, like as easy as setting some flag in azure configuration or modifying app and writing tracing logs explicitly.
The App Insights -> Transaction Search in the portal will show the requests and trace messages but it will only indicate that the function made a HTTP POST call, the response code and duration of that call, it will not show the payload details, so the function app explicitly need to log those details as TRACE info using ILogger instance that is injected to the function.

Can I use a custom hostname for Azure Event grid Topic

I have an Azure Event Grid topic:
https://xxx.westeurope-1.eventgrid.azure.net/api/events
Is there any way to direct clients to publish events to https://xxx.mydomain.com/api/events without getting certificate validation errors, etc.?
It would appear, after researching further documentation and speaking to Microsoft that this is currently not possible. If you create a CNAME entry in your own DNS to point to the Azure fqdn of the endpoint, certificate errors are (understandably) generated.
You could use some type of API gateway to accomplish this. The gateway would have your desired domain name and route for the public to submit requests. A service
behind the gateway would forward the request to the event topic's endpoint.
Another option, but based on the same idea mentioned above, would be to use Azure Functions. The function becomes the gateway and the client publishes to the function's endpoint. Code within the Azure Function bundles the request and forwards it to the event topic.
I'm currently using the Functions approach. My function accepts a generic JSON body, validates a few things, packages it up so it has everything the event topic needs (access keys, headers, correct properties for the event schema, etc), and sends it off to the event topic endpoint. If everything works, I send the client a 200 HTTP status from the Azure Function. If there's a problem, I send a 400 or 500 series status as appropriate.

Difference between API and Webhook from a programmer's perspective

I came across the term Webhook recently (in Azure Alerts, Github deployment, etc.). In my effort to understand the difference between API and Webhook, I read the explanations in stackexchange and sendgrid. My understanding is that the difference is in the way an API is invoked. But this sounds confusing. I think any API does following,
may accept some inputs
perform some action
respond to the caller
If the above mentioned is true, then there is no need for APIs to be categorised based on how they are invoked. At least, this is true from coding perspective as the API is going to work anyway as long as it is invoked and gets the inputs (if required).
Just to explain my understanding of these terms with an example, Azure currently offers (in preview mode as of writing this question) creating Action Groups while setting up Alerts. Two of the alert types supported are Azure Function and Webhook. I could create a Http Trigger Azure function and use it in two Alerts where first one is of Azure Function type and the second one is of the Webhook type. To my surprise, the Webhook type Alert works even though I am using a Http Trigger Azure function (note that, Azure offers template for creating Webhook Azure function too). Below given is the Http Trigger Azure Function I wrote to setup the Webhook for Alert (actual link to code with instructions).
#r "Newtonsoft.Json"
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public async static Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log, ICollector<string> outputQueueItem)
{
log.Info("C# HTTP trigger function processed a request.");
string jsonContent = await req.Content.ReadAsStringAsync();
JToken activityLog = JObject.Parse(jsonContent.ToString())
.SelectToken("data.context.activityLog");
//captures the details of the resource group being modified
log.Info(string.Format("Resource group '{0}' was {1} on {2}.",
(string)activityLog["resourceGroupName"],
((string)activityLog["subStatus"]).ToLower(),
(DateTime)activityLog["eventTimestamp"]));
return req.CreateResponse(HttpStatusCode.OK);
}
At least in the Azure example, it looks like the Webhook Azure function does nothing special, otherwise the Webhook type Alert would not have worked with a Http Trigger Azure function. So, is there any difference in the way of coding or thought process when you code a REST API and Webhook using WebAPI?
Functionally, there is no real difference, but they are different.
With an API, the author defines the spec (audience, protocol, verb, arguments, etc.) for the given endpoint, whereas with a Web Hook, this is specified by a third party.
It is important to maintain the differentiation, as it will help you or other developers to understand how the function is being consumed, and, in the case of a Web Hook, what parts of your solution will be impacted if its intended consumer changes its specification.
After diffing through both Azure HTTP Trigger as well as the "Generic Web hook" functions, I see no difference except that the Web hook mode are offered on both constructs and can be interchangeably used, where the Web hook mode needs a API key whereas its optional on the HTTP Trigger construct.
The Generic JSON option lets you dictate how your Web hook can look like unlike third party providers like Git or Slack.

Right way to implement calling a callback URL in Azure

If I have an API-only app in Azure App Service where users can send a callback URL in the request. The app sends a POST request to the callback URL upon completion.
There are some complexities in implementing calling a callback URL, for example: retries, time between retries, etc.
Is there a service, or set of services, in Azure that can help me implement a callback URL? For example, in AWS the Simple Notification Service (SNS) allows me to send a "push" to a HTTPS endpoint with retries, etc.
Without knowing what sort of context you might need for your callback, you could drop a message in a service bus queue or topic and then write a simple logic app or function which is triggered by the presence of a new message in the queue or topic.
A logic app would provide a solution with no code, only config. A function would require some very basic coding. Logic apps have built in retry features.
Here is an example which somewhat resembles what I think you're after.

Resources