Miha Jakovac

Logo

.NET & DevOps Engineer | Cloud Specialist | Team Enabler

My name is Miha and I've been tinkering with computers for some time now. I remember getting Pentium 100 in the late '90s and that's how it all started.

Specialities:

4 January 2021

Liveness check tool for your HTTP services

by Miha J.

I like using tools. And as you may already know, I also enjoy writing tools. The one I will present today is about checking the health of HTTP API endpoints. It’s a simple tool that returnes the HTTP endpoint status code.

OK, here is the core code of the tool:

//Copy and paste code
using QAToolKit.Engine.Probes.Probes;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace MyApp
{
    class Program
    {
        private static async Task Main(string[] args)
        {
            var hcs = new string[] {
                $"https://users-dev.api.com/hc",
                $"https://orders-dev.api.com/hc",
                $"https://sites-dev.api.com/hc",
                $"https://files-dev.api.com/hc"
            };

            foreach (var service in hcs)
            {
                var httpProbe = new HttpProbe(
                    new Uri(service),
                    HttpMethod.Get);
                var result = await httpProbe.Execute();
                Console.WriteLine($"[{result.StatusCode}] - {service}");
            }
        }
    }
}

15 lines of code! We are using QAToolKit’s Network Probes Nuget Package, to create HTTP probes. Here is the output:

[OK] - https://users-dev.api.com/hc
[OK] - https://orders-dev.api.com/hc
[OK] - https://sites-dev.api.com/hc
[OK] - https://files-dev.api.com/hc

Simple and useful. :)

tags: c# - tool - qatoolkit - http