AshTypescript.TypedController (ash_typescript v0.15.3)

Copy Markdown View Source

Standalone Spark DSL for defining typed controller routes.

Generates TypeScript path helper functions and a thin Phoenix controller from routes configured in the DSL. This is completely independent from Ash.Resource — routes contain colocated arguments and handler functions.

Usage

defmodule MyApp.Session do
  use AshTypescript.TypedController

  typed_controller do
    module_name MyAppWeb.SessionController

    route :login do
      method :post
      run fn conn, params -> Plug.Conn.send_resp(conn, 200, "OK") end
      argument :code, :string, allow_nil?: false
    end

    route :auth do
      method :get
      run fn conn, _params -> Plug.Conn.send_resp(conn, 200, "Auth") end
    end
  end
end

Options

  • :extensions (list of module that adopts Spark.Dsl.Extension) - A list of DSL extensions to add to the Spark.Dsl

  • :otp_app (atom/0) - The otp_app to use for any application configurable options

  • :fragments (list of module/0) - Fragments to include in the Spark.Dsl. See the fragments guide for more.