Record HTTP requests and inspect them in two LiveViews: a filterable call list and a per-path tally.
This package is not on Hex yet. License and ownership are still open. Depend on it from git or a local path until then.
Add the dependency:
def deps do
[
{:api_tally, path: "../api_tally"}
# later: {:api_tally, "~> 0.1.0"}
]
endConfigure the host repo (required) and router (needed for tally to list unused routes):
# config/config.exs
config :api_tally,
repo: MyApp.Repo,
router: MyAppWeb.Router,
actor_assign_keys: [:current_user, :current_admin_user],
actor_email_field: :email
# optional override, (conn) -> email | nil
# actor: {MyApp.ApiTally, :actor, []}Generate and run the migration:
mix api_tally.install
mix ecto.migrateRecord requests from any pipeline:
pipeline :browser do
plug :accepts, ["html"]
# ...
plug ApiTally.Plug
end
pipeline :api do
plug :accepts, ["json"]
plug ApiTally.Plug
endMount the LiveViews inside a session that already has auth and a layout:
scope "/admin", as: :admin do
pipe_through [:browser, :require_admin]
require ApiTally.Router
live_session :admin do
ApiTally.Router.live_routes()
# /admin/api_tracker and /admin/tally
end
endThe UI ships its own scoped CSS. The host does not need Tailwind.
The plug stores an email (or other identifier) on each row.
- A plug-level
actor:option wins for that pipeline. - Otherwise
config :api_tally, :actor(MFA orfun(conn)). - Otherwise the first non-nil assign in
actor_assign_keys, readingactor_email_field.
plug ApiTally.Plug, actor: &MyApp.Accounts.api_tally_actor/1Do not run mix hex.publish until a license and Hex owner are chosen.