View Source Provider (schema_provider v0.0.1)

The Provider module provides a macro for generating RESTful CRUD routes for a given Ecto schema in a Plug-based application.

The mount macro automatically creates routes for listing, showing, creating, updating, and deleting resources. Custom routes can also be defined within the do block.

Summary

Functions

The mount/2 macro is used to generate RESTful CRUD routes for a specified schema. It accepts the following options

Functions

Link to this macro

mount(path, opts)

View Source (macro)

The mount/2 macro is used to generate RESTful CRUD routes for a specified schema. It accepts the following options:

  • :path: The base path where the routes will be mounted.
  • :schema: The Ecto schema module for which the routes are being generated.
  • :functions: A keyword list of custom handler functions for specific routes. Available keys are :list, :get, :create, :update, and :delete.
  • do: The block where custom routes can be defined.

Example

mount "/users", schema: MyApp.Schema.User do
  get "/custom/endpoint" do
    send_resp(conn, 200, "Custom endpoint")
  end
end

This will generate the following routes:

  • GET /users - Lists all users.
  • GET /users/:id - Shows a specific user.
  • POST /users - Creates a new user.
  • PUT /users/:id - Updates an existing user.
  • DELETE /users/:id - Deletes a specific user.

The schema module must implement the Provider.Schema behavior, which enforces the presence of a changeset/2 function.