Programming Practices to API Uptime Monitoring

One of the more basic yet very useful thing I do when I have build a backend web API is to have an endpoint that is used solely for monitoring the server uptime.

Like:


GET /health
{
  "health" : true,
  "startTime" : "2024-09-20T13:45:07.441Z"
  "commit" : "e21c64e362647df3baf21e071bfed88a4f88b674",
}
      
    

It's a GET endpoint that doesn't accept any parameters and returns a JSON object.

Other than returning the time when the server started, I find it useful to also include the git commit hash of the code that is running for troubleshooting purposes.

So other than setting up an uptime monitoring service like Ping Now to access this endpoint, you can also manually `curl` it to see if your deployment is successful by looking at the git commit hash.

by @hboon

fa30f1809b4fe64075fe29973e83a44d4fc6c229