Coverage StatusHex versionHex DocsBuild StatusDeps Status

ServerUtils

This project has several module utils to handle common tasks in a server, like authorization params parsing.

Features:

Installation

Add to dependencies

def deps do
[{:server_utils, "~> 0.1.5"}]
end
mix deps.get

Configuration

Pagination

Configure default pagination params:

config :server_utils,
page_size_key: "page_size",
page_number_key: "page_number",
max_page_size: 25,
page_size: 10,
page_number: 1
config :server_utils,
cursor_key: "cursor",
number_of_items_key: "number_of_items",
default_cursor: "",
default_number_of_items: 25,
max_number_of_items: 50

Usage

Check the documentation for the different available plugs.

Pagination

Set the plug in your router file to use it in a pipeline:

pipeline :paginated do
plug(ServerUtils.Plugs.CursorPageRequest)
end
scope "/" do
pipe_through([:paginated])
get("/stuff", MyApp.StuffController, :get_stuff)
end

Depending on the plug used, CursorPageRequest.t() or PageParams.t() will be inject in the Plug.Conn.t() struct:

defmodule MyApp.StuffController do
use MyApp, :controller
def get_stuff(conn, params) do
cursor_page_request = conn.private[:page_request]
# Some other code using the cursor page request...
end
end