plug

Plug

Composable web middleware specification and connection adapter for Elixir

Details

Language / Topic
elixirElixir
Category
framework
Compatible Frameworks
plug

Rules

balanced
- Build request pipelines with `Plug.Builder` — each plug transforms the `%Plug.Conn{}` struct in sequence.
- Use `Plug.Router` for routing with `get/post/put/delete` macros — each route is a function that receives `conn` and `opts`.
- Call `Plug.Conn.send_resp/3` to send responses — always set status code and body. Use `put_resp_content_type/2` for JSON APIs.
- Use `Plug.Parsers` in your pipeline to automatically parse JSON, URL-encoded, and multipart request bodies.
- Implement `init/1` for compile-time option validation and `call/2` for runtime request handling.
- Use `Plug.Builder` to define reusable plug pipelines with `plug MyPlug, opts` macros.
- Use `Plug.Conn` functions (`put_resp_content_type`, `send_resp`, `assign`) to build responses.
- Chain plugs in order: parsing → auth → rate limiting → routing → response.