DSL for your Elixir web application
Documentation: hexdocs.pm/francis
To install it, add the following to your mix.exs:
{:francis, "~> 0.1.0"}
Deploy it with 2 commands
mix francis.release
fly launch
defmodule GetJson do
@moduledoc """
Handle Easily GET, POST, PUT and DELETE requests
Automatically parse JSON body and params
and responses with JSON
"""
use Francis
get("/hello", fn _ -> %{hello: :world} end)
get("/:name", fn %{params: params} -> params["name"] end)
post("/", fn conn -> conn.body_params end)
end
defmodule WebSocket do
@moduledoc """
Sets up a WebSocket endpoint
and use pattern match to handle messages
"""
use Francis
ws("ws", fn "ping", socket ->
Process.send_after(socket.transport, "pong", 1000)
{:reply, "pong"}
end)
end
defmodule Static do
@moduledoc """
Serve static files from a directory
"""
use Francis,
static: [from: "pric/static", to: "/"]
unmatched(fn _ -> "not found" end)
end
defmodule NotFound do
@moduledoc """
Simple not found handler setup
"""
use Francis
unmatched(fn _ -> "not found" end)
end
It also enables you to build simple htmx.org websites with a small code footprint using github.com/filipecabaco/francis_htmx
To install it in your project, add the following to your mix.exs:
{:francis_htmx, "~> 0.1.0"}
For more information and contribute, check out the repository at github.com/filipecabaco/francis
Check the code for this website at github.com/filipecabaco/francis_site