Handle HTTP requests with Phoenix controllers including actions, parameters, rendering, flash messages, and redirects
View on GitHubTheBushidoCollective/han
jutsu-phoenix
January 24, 2026
Select agents to install to:
npx add-skill https://github.com/TheBushidoCollective/han/blob/main/jutsu/jutsu-phoenix/skills/phoenix-controllers/SKILL.md -a claude-code --skill phoenix-controllersInstallation paths:
.claude/skills/phoenix-controllers/# Phoenix Controllers
Phoenix controllers are the intermediary modules between the router and views in a Phoenix application. They handle HTTP requests, process parameters, interact with contexts, and determine what response to send back to the client. Controllers are stateless and receive a connection struct (`conn`) that represents the current HTTP request.
## Basic Controller Structure
The simplest Phoenix controller uses the `HelloWeb, :controller` macro and defines actions as functions that receive the connection and parameters:
```elixir
defmodule HelloWeb.PageController do
use HelloWeb, :controller
def home(conn, _params) do
render(conn, :home, layout: false)
end
end
```
Each controller action receives:
- `conn` - The `Plug.Conn` struct representing the HTTP request/response
- `params` - A map containing request parameters from the URL, query string, and request body
## Controller Actions and Parameter Handling
### Extracting Specific Parameters
Use pattern matching to extract specific parameters from the params map:
```elixir
defmodule HelloWeb.HelloController do
use HelloWeb, :controller
def show(conn, %{"messenger" => messenger}) do
render(conn, :show, messenger: messenger)
end
end
```
### Accessing Full Parameter Map
To access both a specific parameter and the full params map, use pattern matching with the `=` operator:
```elixir
def show(conn, %{"messenger" => messenger} = params) do
# Access to both messenger and the full params map
render(conn, :show, messenger: messenger)
end
```
### Ignoring Parameters
When an action doesn't need parameters, prefix the variable with an underscore to avoid compiler warnings:
```elixir
def index(conn, _params) do
render(conn, :home)
end
```
### Renaming Actions
Action names can be customized independently of the template name:
```elixir
defmodule HelloWeb.PageController do
use HelloWeb, :controller
def index(conn, _params) do
# Renders :home template but action is