Lazymaru

Elixir copy of grape for creating REST-like APIs.

Build Statushex.pm Version

Usage

defmodule Router.User do
use Lazymaru.Router
namespace :user do
route_param :id do
get do
%{ user: params[:id] } |> json
end
desc "description"
params do
requires :age, type: Integer, values: 18..65
requires :sex, type: Atom, values: [:male, :female], default: :female
group :name, type: Map do
requires :first_name
requires :last_name
end
optional :intro, type: String, regexp: ~r/^[a-z]+$/
optional :avatar, type: File
optional :avatar_url, type: String
exactly_one_of [:avatar, :avatar_url]
end
post do
...
end
end
end
end
defmodule Router.Homepage do
use Lazymaru.Router
resources do
get do
%{ hello: :world } |> json
end
mount Router.User
end
end
defmodule MyAPP.API do
use Lazymaru.Router
plug Plug.Static "/static", "/my/static/path/"
mount Router.Homepage
def error(conn, _e) do
"Server Error" |> text(500)
end
end

then add the lazymaru to your config/config.exs

config :lazymaru, MyAPP.API
port: 8880

For more info, you can move to Getting Started Guide and Router Guide

TODO