PhoenixAssets. Generators. Routes
(PhoenixAssets v0.1.0)
View Source
Generates typed Phoenix endpoint helpers from the router.
Emits routes.ts -- typed builders for the server endpoints the frontend
calls directly. Which routes qualify is governed by the configured path
prefixes (default /shapes and /api):
config :phoenix_assets,
endpoint_prefixes: ["/api", "/shapes", "/webhooks"]It deliberately does not generate page routes: in a SvelteKit app the page-route authority is the frontend, so only the Phoenix-owned endpoints belong in a generated contract.
Each route becomes a function keyed by its controller action (or route
helper), taking its path parameters and returning the URL with parameters
URL-encoded. When two routes share an action name, the later one is
qualified with its controller (articleIndex); a numeric suffix is the
last resort. Output is sorted by name for deterministic diffs.
Example output
export const routes = {
articleBySlug: (slug: string | number) =>
`/shapes/articles/${encodeURIComponent(String(slug))}`,
health: () => "/api/health",
publicArticles: () => "/shapes/articles",
} as const
Summary
Functions
Generates the routes.ts contract, or nil when no router is configured.
Functions
@spec generate(PhoenixAssets.Context.t()) :: PhoenixAssets.GeneratedFile.t() | nil
Generates the routes.ts contract, or nil when no router is configured.