wisp_flash
Functions
pub fn get_flash(
request: Request(Connection),
set_in_context: fn(Option(String), Option(String)) -> a,
next: fn(a) -> Response(Body),
) -> Response(Body)
Get the flash message and kind. This middleware goes around your request. This gets the values from the cookies and then deletes them. This requires a function to set the flash values in your context. After putting these values in the context, you can use them to render alerts in your view.
Example
let set_in_context = fn(kind: Option(String), message: Option(String)) {
Context(..ctx, flash_kind: kind, flash_message: message)
}
use ctx <- wisp_flash.get_flash(request, set_in_context)
pub fn get_flash_in(
request: Request(Connection),
) -> #(Option(String), Option(String))
Just the incoming part of the get_flash around middleware. This gives you the values to put in the context.
Example
let #(kind, message) = wisp_flash.get_flash_in(request)
pub fn get_flash_out(
response: Response(Body),
request: Request(Connection),
) -> Response(Body)
The outgoing part of the get_flash around middleware. This deletes the cookies.
Example
response |> get_flash_out(request)
pub fn set_flash(
response response: Response(Body),
request request: Request(Connection),
kind kind: String,
message message: String,
) -> Response(Body)
Set a flash message in the session cookie. This will store two cookies. One for the message and one for the notification kind.
Example
wisp.redirect("/home")
|> wisp_flash.set_flash(request, "success", "Document Saved")