plug_rest v0.5.0 PlugRest.Router

A DSL to supplement Plug Router with a resource-oriented routing algorithm.

It provides a macro to generate routes that dispatch to specific resource handlers. For example:

defmodule MyApp.Router do
  use PlugRest.Router

  resource "/pages/:page", PageResource
end

The resource/2 macro accepts a request of format "/pages/VALUE" and dispatches it to the PageResource module, which must adopt the PlugRest.Resource behaviour by implementing one or more of the callbacks which describe the resource.

The macro accepts an optional initial state for the resource. For example:

resource "/pages/:page", PageResource, %{some_option: true}

Because the router builds on Plug’s own Router, you can add additional plugs into the pipeline. See the documentation for Plug.Router for more information.

Summary

Macros

Main API to define resource routes

Macros

resource(path, handler, handler_state \\ [])

Main API to define resource routes.

It accepts an expression representing the path, the name of a module representing the resource, and an optional initial state.

Examples

resource "/pages/:page", PageResource, %{some_option: true}