Upgrade Instructions From v0.9
Route and Mount
A plug-router
means the router compiled into a plug
and handle connections by call/2
function.
v0.9.x
Every router is a plug-router
.
When Router.A
mounted to Router.B
, Router.A.call/2
will be executed. If a halted plug returned, it means that this connection is matched with an endpoint within Router.A
or router mounted to Router.A
.
v0.10.0
Router don't compile into a plug
by default.
When Router.A
mounted to Router.B
, all routes within Router.A
will be merged into Router.B
.
If Router.B
is a plug-router
, a call/2
function will be defined for version and path matching.
There're two way to defined a router as a plug-router
:
- Define it within
config.exs
viaconfig :maru, MyRouterModule, xxxx
- Define it within
defmodule
block viause Maru.Router, make_plug: true
Overridable and Top-Level plugs
Now plugs are bound to endpoint and could be override.
If you need a Top-Level plug which is called before route, write them within before
block.
plug_overriable
is not supported withinbefore
block.before
block only works with plug-router.
Remove build-in Plug.Parser
So, you need to add something like these lines to your plug-router
manually.
plug Plug.Parsers,
pass: ["*/*"],
json_decoder: Poison,
parsers: [:urlencoded, :json, :multipart]
Merge Coercion and ParamType
Now they're both replaced by Maru.Types
.
If you want to define your own type, defined it as Maru.Types.MyDate
and used it like this: requires :date, type: MyDate
.
By the way, you need to use Maru.Type
when you define Maru.Types.MyDate
. And the parser function should be defined as parse/2
instead of from/1
.
Exception Handler
Exception handlers defined by rescue_from
DSL only works with plug-router now.
Test Environment
Maru generates several helper functions to run test
. By default test works when MIX_ENV=test
. If you use another environment for your test, you should add such lines to your config.exs
file:
config :maru, MyApp,
test: true
Updated less than a minute ago