Reputation: 1446
What is the best way to test API endpoints within azure? I am looking to get alerted if an endpoint is not working.
Upvotes: 3
Views: 7647
Reputation: 427
you can write a custom Azure Function to report Telemetry to Application Insight. See: https://github.com/rbickel/Azure.Function.AppInsightAvailabilityTest
Upvotes: 0
Reputation: 8491
I suggest you create a WebJob to test your API endpoints. In your WebJob, you could use a TimerTrigger to run the test function timely(For example, every 2 minutes).
To use TimerTrigger, you need to install Microsoft.Azure.WebJobs.Extensions package using NuGet. After that, you could configure the WebJob to use the timer extension using following code.
static void Main()
{
var config = new JobHostConfiguration();
//Configure WebJob to use TimerTrigger
config.UseTimers();
var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.RunAndBlock();
}
In the function, you could send a request to your Web API. If you can't get the response from the server or the response status is not equal to 200 OK, it means that the Web API is not useable.
public static void StartupJob([TimerTrigger("0 */2 * * * *", RunOnStartup = true)] TimerInfo timerInfo)
{
WebRequest request = WebRequest.Create("URL of your api");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response == null || response.StatusCode != HttpStatusCode.OK)
{
//API is not useable
}
}
Upvotes: 0