A healthcheck endpoint is one of best things you can add to your API
Whilst scrolling on Twitter earlier (yes, I still refuse to call it X), I stumbled across a Tweet by Gary Clarke:
🧑‍⚕️ A healthcheck endpoint is a simple API route that acts as a service’s heartbeat, showing if it’s alive & healthy.
— Gary Clarke (@garyclarketech) March 16, 2025
The Laravel Microservice course is released on 31st March 🚀
…learn more and grab discount here 👇https://t.co/fxjfvAuYNb pic.twitter.com/LV0jFoe7WT
This got me thinking about all of the APIs I've built and aside from one or two, I naturally end up building a healthcheck endpoint, just to verify the thing actually works.
The endpoint itself doesn't need to do anything fancy. Although the example in Gary's screenshot returns some JSON, I actually tend to just return a 200 OK response. This way, I can see if the API is up and make sure that I can use my API token to successfully authenticate with it.
Here's the endpoint for a SaaS I'm currently working on:
public function __invoke(Request $request): JsonResponse {
return response()->json(['status' => 'ok']);
}Example Healthcheck Endpoint
I can then create this in something like Postman as a request, send it to my API and ensure it works OK.