GUIDES
GUIDESDOCS
GUIDES
These docs are for v0.10. Click to read the latest docs for v0.13.

Basic Usage

Install

  1. Create a new application
mix new my_app
  1. Add maru to your mix.exs dependencies:
def deps do
    [ {:maru, "~> 0.10"} ]
  end
  1. List :maru as your application dependencies:
def application do
    [ applications: [:maru] ]
  end

Basic Router

defmodule MyAPP.Router.Homepage do
    use Maru.Router

    get do
      json(conn, %{ hello: :world })
    end
  end

  defmodule MyAPP.API do
    use Maru.Router

    mount MyAPP.Router.Homepage

    rescue_from :all do
      conn
      |> put_status(500)
      |> text("Server Error")
    end
  end

Config

config :maru, MyAPP.API,
    http: [port: 8880]

Run server

$ mix deps.get

$ iex -S mix
Erlang/OTP 17 [erts-6.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
Interactive Elixir (1.0.4) - press Ctrl+C to exit (type h() ENTER for help)

17:42:17.691 [info]  Running Elixir.API with Cowboy on http://127.0.0.1:8880
iex(1)> 

$ curl 127.0.0.1:8880
{"hello":"world"}

Generate routes documents

$ MIX_ENV=dev mix maru.routes