GUIDES
GUIDESDOCS
GUIDES

Work With Phoenix

Here is a simple example. phoenix_maru

1. create phoenix project

Checkout official phoenix guides.

$ mix phoenix.new phoenix_maru

2. build RESTful API by Maru

defmodule PhoenixMaru.API do
  use Maru.Router,  make_plug: true

  get do
    "API works!"
  end
end

3. forward request to Maru

Edit web/router.ex

defmodule PhoenixMaru.Router do
  use PhoenixMaru.Web, :router

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/", PhoenixMaru do
    pipe_through :browser # Use the default browser stack

    get "/", PageController, :index
  end

  # Other scopes may use custom stacks.
  scope path: "/api" do
    pipe_through :api

    forward "/", PhoenixMaru.API
  end
end