Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

ApiTally

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.

Install

Add the dependency:

def deps do
  [
    {:api_tally, path: "../api_tally"}
    # later: {:api_tally, "~> 0.1.0"}
  ]
end

Configure 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.migrate

Record requests from any pipeline:

pipeline :browser do
  plug :accepts, ["html"]
  # ...
  plug ApiTally.Plug
end

pipeline :api do
  plug :accepts, ["json"]
  plug ApiTally.Plug
end

Mount 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
end

The UI ships its own scoped CSS. The host does not need Tailwind.

Actor

The plug stores an email (or other identifier) on each row.

  1. A plug-level actor: option wins for that pipeline.
  2. Otherwise config :api_tally, :actor (MFA or fun(conn)).
  3. Otherwise the first non-nil assign in actor_assign_keys, reading actor_email_field.
plug ApiTally.Plug, actor: &MyApp.Accounts.api_tally_actor/1

Not yet published

Do not run mix hex.publish until a license and Hex owner are chosen.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages