View Source Francis (Francis v0.1.6)
Module responsible for starting the Francis server and to wrap the Plug functionality
This module performs multiple tasks:
- Uses the Application module to start the Francis server
- Defines the Francis.Router which uses Francis.Plug.Router, :match and :dispatch
- Defines the macros get, post, put, delete, patch and ws to define routes for each operation
You can also set the following options:
- :bandit_opts - Options to be passed to Bandit
- :plugs - List of plugs to be used by Francis
Summary
Functions
Defines a DELETE route
Defines a GET route
Defines a PATCH route
Defines a POST route
Defines a PUT route
Defines an action for umatched routes and returns 404
Defines a WebSocket route that sends text type responses
Functions
@spec delete(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
Defines a DELETE route
Examples
defmodule Example.Router do
use Francis
delete "/hello", fn conn ->
"Hello World!"
end
end
@spec get(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
Defines a GET route
Examples
defmodule Example.Router do
use Francis
get "/hello", fn conn ->
"Hello World!"
end
end
@spec patch(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
Defines a PATCH route
Examples
defmodule Example.Router do
use Francis
patch "/hello", fn conn ->
"Hello World!"
end
end
@spec post(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
Defines a POST route
Examples
defmodule Example.Router do
use Francis
post "/hello", fn conn ->
"Hello World!"
end
end
@spec put(String.t(), (Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
Defines a PUT route
Examples
defmodule Example.Router do
use Francis
put "/hello", fn conn ->
"Hello World!"
end
end
@spec unmatched((Plug.Conn.t() -> binary() | map() | Plug.Conn.t())) :: Macro.t()
Defines an action for umatched routes and returns 404
Defines a WebSocket route that sends text type responses
Examples
defmodule Example.Router do
use Francis
ws "/hello", fn _ ->
"Hello World!"
end
end