Basic Usage
Install
- Create a new application
mix new my_app
- Add maru to your
mix.exs
dependencies:
defp deps do
[ {:maru, "~> 0.11"} ]
end
- List
:maru
as your application dependencies: (you don't need do this for elixir ~> 1.4)
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
plug Plug.Parsers,
pass: ["*/*"],
json_decoder: Poison,
parsers: [:urlencoded, :json, :multipart]
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
Updated less than a minute ago