PhoenixKit.API.Paths (phoenix_kit v3.0.0)

Copy Markdown View Source

The one table of API paths. The router macro (PhoenixKitWeb.Integration) forwards every entry to its plug, and PhoenixKit.API.BodyGuard guards every entry, so the two cannot disagree about where the API lives.

The axis of the API is the audience, not a module: modules own the names of their tools (catalogue.set_prices), the paths are

/api/admin/v1   /mcp/admin     the admin audience, with a key
/api/public/v1  /mcp/public    the public audience, without one

under the kit's URL prefix. The segment that names the public audience is public_segment/0, the only place it is spelled: renaming the public prefix is a change of that one line.

Entries

entries/0 lists {segments, audience, cors?}:

  • segments, the path under the URL prefix, split by /;
  • audience, :admin or :public, which decides the plug's options and the switch PhoenixKit.API.BodyGuard looks at;
  • cors?, whether the answers carry the CORS headers of the public REST audience (PhoenixKit.API.REST), the guard's included;

Anything that builds a URL for a client (PhoenixKit.API.OpenAPI, PhoenixKit.API.PublicDiscovery) takes rest_path/1 and mcp_path/1, which are the only paths the API answers on.

Summary

Functions

Every path the API answers on. See the moduledoc for the shape.

The canonical path of the MCP endpoint of audience, without the URL prefix.

The path of segments as forward takes it: "/api/admin/v1".

The plug that serves the path made of segments: REST under api, MCP under mcp.

The options of the forward of entry: the audience.

The path segment that names the public audience in /api/<segment>/v1 and /mcp/<segment>: the one place it is spelled.

The canonical path of the REST API of audience, without the URL prefix.

Types

entry()

@type entry() :: {segments(), :admin | :public, boolean()}

segments()

@type segments() :: [String.t()]

Functions

entries()

@spec entries() :: [entry()]

Every path the API answers on. See the moduledoc for the shape.

mcp_path(atom)

@spec mcp_path(:admin | :public) :: String.t()

The canonical path of the MCP endpoint of audience, without the URL prefix.

path(segments)

@spec path(segments()) :: String.t()

The path of segments as forward takes it: "/api/admin/v1".

plug(list)

@spec plug(segments()) :: module()

The plug that serves the path made of segments: REST under api, MCP under mcp.

plug_opts(arg)

@spec plug_opts(entry()) :: keyword()

The options of the forward of entry: the audience.

public_segment()

@spec public_segment() :: String.t()

The path segment that names the public audience in /api/<segment>/v1 and /mcp/<segment>: the one place it is spelled.

rest_path(atom)

@spec rest_path(:admin | :public) :: String.t()

The canonical path of the REST API of audience, without the URL prefix.