From 53f4bc5ecffda8c1955896f2a5e0456d8b54e457 Mon Sep 17 00:00:00 2001 From: Mike Cifelli Date: Mon, 18 Mar 2024 16:12:41 -0400 Subject: [PATCH] Add a health endpoint --- .../controllers/api/v1/health_controller.ex | 7 +++++++ lib/chronoscope_web/router.ex | 6 ++++++ .../controllers/api/v1/health_controller_test.exs | 12 ++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 lib/chronoscope_web/controllers/api/v1/health_controller.ex create mode 100644 test/chronoscope_web/controllers/api/v1/health_controller_test.exs diff --git a/lib/chronoscope_web/controllers/api/v1/health_controller.ex b/lib/chronoscope_web/controllers/api/v1/health_controller.ex new file mode 100644 index 0000000..8c3d7f3 --- /dev/null +++ b/lib/chronoscope_web/controllers/api/v1/health_controller.ex @@ -0,0 +1,7 @@ +defmodule ChronoscopeWeb.API.V1.HealthController do + use ChronoscopeWeb, :controller + + def get(conn, _params) do + json(conn, %{healthy: true}) + end +end diff --git a/lib/chronoscope_web/router.ex b/lib/chronoscope_web/router.ex index 87dd9f9..72c4a12 100644 --- a/lib/chronoscope_web/router.ex +++ b/lib/chronoscope_web/router.ex @@ -20,6 +20,12 @@ defmodule ChronoscopeWeb.Router do get "/", PageController, :home end + scope "/api/v1", ChronoscopeWeb.API.V1 do + pipe_through :api + + get "/health", HealthController, :get + end + scope "/api/v1/nts", ChronoscopeWeb.API.V1.NTS do pipe_through :api diff --git a/test/chronoscope_web/controllers/api/v1/health_controller_test.exs b/test/chronoscope_web/controllers/api/v1/health_controller_test.exs new file mode 100644 index 0000000..7d7ccf2 --- /dev/null +++ b/test/chronoscope_web/controllers/api/v1/health_controller_test.exs @@ -0,0 +1,12 @@ +defmodule ChronoscopeWeb.API.V1.HealthControllerTest do + use ChronoscopeWeb.ConnCase, async: true + + test "indicates health", %{conn: conn} do + response = + conn + |> get(~p"/api/v1/health") + |> json_response(200) + + assert %{"healthy" => true} == response + end +end