a Elixir copy of grape, which is an opinionated micro-framework for creating REST-like APIs in Ruby. In Development.
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, range: 18..65
requires :sex, type: Atom, default: :female
optional :intro, type: String, regexp: ~r/^[a-z]+$/
optional :avatar, type: File
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 MyMiddleware do
use Lazymaru.Middleware
def prepare(conn) do
IO.puts "prepare"
conn
end
def call(conn, app) do
try do
app.(conn)
rescue
_ ->
"Not Found" |> text(404)
end
end
def finish(conn) do
IO.puts "finish"
conn
end
end
defmodule MyAPP.API do
use Lazymaru.Server
port 8880
rest Router.Homepage
middleware MyMiddleware
static "/static", "/my/static/path/"
end
MyAPP.API.start
- [ ] realtime connection
- [X] params DSL
- [X] header DSL
- [X] assign DSL
- [ ] generate docs by desc DSL
- [X] middleware support
- [ ] custom params validators
- [X] helper DSL