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