---
agentTools:
  projectIndex: https://maru.readme.io/llms.txt
---

# Pipelines

Different with most plug based framework, `plug` and `plug_overridable` are bound to endpoint.
It means that this type of plugs called after route. If you need a top-level plug, you should defined it within `before` block. There's a thorough example:

[block:code]
{
  "codes": [
    {
      "code": "defmodule API do\n  use Maru.Router\n  \n  before do\n    plug Plug.Static, at: \"/static\", from: \"/my/static/path/\"\n  end\n  plug Plug.Logger\n  plug_overridable :auth, Auth.Guest\n  \n  pipeline do\n    plug A\n  end\n  post do\n    ...\n  end\n  \n  pipeline do\n    plug B\n    plug_overridable :auth, Auth.Admin\n  end\n  get :admin do\n    ...\n  end\nend",
      "language": "ruby"
    }
  ]
}
[/block]

This router will be executed by such order:

[block:code]
{
  "codes": [
    {
      "code": "conn \n-> `Plug.Static` \n  -> route(:post, [\"/\"])    -> `Plog.Logger` -> `Auth.Guest` -> `A` -> 'endpoint block'\n  -> route(:get, [\"admin\"]) -> `Plug.Logger` -> `Auth.Admin` -> `B` -> 'endpoint block'",
      "language": "text"
    }
  ]
}
[/block]