phoenix-routing
БесплатноБез исполняемых скриптовНе проверенDefine routes and URL helpers in Phoenix applications including resources, scopes, pipelines, and verified routes
от TheBushidoCollective★ 202 звезды на GitHubОб этом скилле
Phoenix Routing
Phoenix routing maps incoming HTTP requests to controller actions. The router is the entry point for all web requests and determines which controller action should handle each request. Phoenix provides powerful routing macros for RESTful resources, scopes, pipelines, and verified routes.
Basic Route Declaration
Single Routes
Define individual routes using HTTP verb macros:
get "/", PageController, :home
Phoenix supports all standard HTTP verbs:
get "/users", UserController, :index
post "/users", UserController, :create
patch "/users/:id", UserController, :update
put "/users/:id", UserController, :update
delete "/users/:id", UserController, :delete
Routes with Dynamic Segments
Capture URL parameters using the :param_name syntax:
get "/hello/:messenger", HelloController, :show
The :messenger segment becomes available in the controller's params map.
Resource Routes
Basic Resource Declaration
Generate all standard RESTful routes with the resources macro:
resources "/users", UserController
This generates eight routes:
GET /users UserController :index
GET /users/:id/edit UserController :edit
GET /users/new UserController :new
GET /users/:id UserController :show
POST /users UserController :create
PATCH /users/:id UserController :update
PUT /users/:id UserController :update
DELETE /users/:id UserController :delete
Limiting Resource Routes
Use :only to generate specific routes:
resources "/users", UserController, only: [:show]
resources "/posts", PostController, only: [:index, :show]
Use :except to exclude specific routes:
resources "/users", UserController, except: [:create, :delete]
Aliasing Resources
Customize the route path helper name with :as:
resources "/users", UserController, as: :person
This generates path helpers like ~p"/person" instead of ~p"/users".
Nested Resources
Create hierarchical resource relationships:
resources "/users", UserController do
resources "/posts", PostController
end
Generated routes include the parent resource ID:
GET /users/:user_id/posts PostController :index
GET /users/:user_id/posts/:id/edit PostController :edit
GET /users/:user_id/posts/new PostController :new
GET /users/:user_id/posts/:id PostController :show
POST /users/:user_id/posts PostController :create
PATCH /users/:user_id/posts/:id PostController :update
PUT /users/:user_id/posts/:id PostController :update
DELETE /users/:user_id/posts/:id PostController :delete
Verified Routes
Using the ~p Sigil
Phoenix provides compile-time verified routes using the ~p sigil:
# Static paths
~p"/users"
~p"/posts/new"
# Dynamic segments with variables
~p"/users/#{user_id}"
~p"/users/#{user_id}/posts/#{post_id}"
Verified Routes with Structs
Pass structs directly to generate paths:
~p"/users/#{@user}"
# Generates: "/users/42"
~p"/users/#{user}/posts/#{post}"
# Generates: "/users/42/posts/17"
Phoenix automatically extracts the ID using the Phoenix.Param protocol.
Benefits of Verified Routes
- Compile-time validation - Catch routing errors during compilation
- Refactoring safety - Route changes are caught immediately
- Type safety - Ensure correct parameter types
- URL slug support - Easy transition to slug-based URLs
Scopes
Basic Scopes
Group routes under a common path prefix:
scope "/admin", HelloWeb.Admin do
pipe_through :browser
resources "/users", UserController
end
Generated paths include the scope prefix:
~p"/admin/users"
Scopes with Aliases
Reduce repetition by aliasing controller modules:
scope "/", HelloWeb do
pipe_through :browser
get "/", PageController, :home
resources "/posts", PostController
end
Nested Scopes
Create hierarchical route organization:
scope "/api", HelloWeb.Api, as: :api do
pipe_through :api
scope "/v1", V1, as: :v1 do
resources "/users", UserController
end
scope "/v2", V2, as: :v2 do
resources "/users", UserController
end
end
Generated path helpers reflect the nesting:
~p"/api/v1/users"
~p"/api/v2/users"
Pipelines
Defining Pipelines
Pipelines group plugs that run for specific routes:
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_live_flash
plug :put_root_layout, html: {HelloWeb.Layouts, :root}
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
Applying Pipelines to Scopes
Use pipe_through to apply pipelines:
scope "/", HelloWeb do
pipe_through :browser
get "/", PageController,
Установить phoenix-routing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
BashReadFAQ
Что делает скилл phoenix-routing?
Define routes and URL helpers in Phoenix applications including resources, scopes, pipelines, and verified routes
Как установить скилл phoenix-routing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл phoenix-routing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic