View Source Francis (Francis v0.1.5)

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

Link to this macro

delete(path, handler)

View Source (macro)

Defines a DELETE route

Examples

defmodule Example.Router do
  use Francis

  delete "/hello", fn conn ->
    "Hello World!"
  end
end
Link to this macro

get(path, handler)

View Source (macro)

Defines a GET route

Examples

defmodule Example.Router do
  use Francis

  get "/hello", fn conn ->
    "Hello World!"
  end
end
Link to this macro

patch(path, handler)

View Source (macro)

Defines a PATCH route

Examples

defmodule Example.Router do
  use Francis

  patch "/hello", fn conn ->
    "Hello World!"
  end
end
Link to this macro

post(path, handler)

View Source (macro)

Defines a POST route

Examples

defmodule Example.Router do
  use Francis

  post "/hello", fn conn ->
    "Hello World!"
  end
end
Link to this macro

put(path, handler)

View Source (macro)

Defines a PUT route

Examples

defmodule Example.Router do
  use Francis

  put "/hello", fn conn ->
    "Hello World!"
  end
end
Link to this macro

unmatched(handler)

View Source (macro)

Defines an action for umatched routes and returns 404

Link to this macro

ws(path, handler)

View Source (macro)

Defines a WebSocket route that sends text type responses

Examples

defmodule Example.Router do
  use Francis

  ws "/hello", fn _ ->
    "Hello World!"
  end
end