lukemathwalker/actix-web-flash-messages

actix-web-flash-messages

Flash messages for actix-web

actix-web-flash-messages

Flash messages for actix-web


Web applications sometimes need to show a one-time notification to the user - e.g. an error message after having failed to login.
These notifications are commonly called flash messages.

actix-web-flash-messages provides a framework to work with flash messages in actix-web, closely modeled after Django's message framework.

How to install

Add actix-web-flash-messages to your dependencies:

By default, actix-web-flash-messages does not provide any storage backend to receive and send flash messages.
You can enable:

  • a cookie-based one, storage::CookieMessageStore, using the cookies feature flag. The cookie store uses a signed cookie to store and retrieve messages;

  • a session-based one, [storage::SessionMessageStore], using the sessions feature flag. The session store attaches flash messages to the current session.

You can provide a different message store by implementing the storage::FlashMessageStore trait.

Examples

You can find examples of application using actix-web-flash-messages on GitHub:

  • cookies;
  • cookie-based sessions;
  • Redis-based sessions.

The Structure of a Flash Message

FlashMessages are made of a Level and a string of content.

The message level can be used for filtering and rendering - for example:

  • Only show flash messages at info level or above in a production environment, while retaining debug level messages for local development;
  • Use different colours, in the UI, to display messages (e.g. red for errors, orange for warnings, etc.);

You can build a FlashMessage via FlashMessage::new by specifying its content and Level.
You can also use the shorter level-based constructors - e.g. FlashMessage::info.

Enabling Flash Messages

To start sending and receiving flash messages you need to register FlashMessagesFramework as a middleware on your actix_web's App:

You will then be able to:

  • extract FlashMessages from incoming requests using the IncomingFlashMessages extractor;
  • send FlashMessages alongside the outgoing response using FlashMessage::send.

Framework Configuration

There are a few knobs that you can tweak when it comes to FlashMessagesFramework.
Use FlashMessagesFramework::builder to get access to its fluent configuration API, built around FlashMessagesFrameworkBuilder.

Minimum Level

By default, FlashMessagesFramework will only dispatch messages at info-level or above, discarding debug-level messages.
You can change this setting using FlashMessagesFrameworkBuilder::minimum_level.

Message Storage

actix-web-flash-messages provides a cookie-based implementation of flash messages, storage::CookieMessageStore, using a signed cookie to store and retrieve messages.
You can provide a different message store by implementing the storage::FlashMessageStore trait.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option. Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Information - Updated Aug 03, 2022

Stars: 29
Forks: 5
Issues: 0
Http

336

An HTTP/2 implementation in Rust

implementation allows users to issue a number of requests before blocking to

An HTTP/2 implementation in Rust

http-auth-basic

The "Basic" Hypertext Transfer Protocol (HTTP) authentication scheme, transmits credentials as user-id/password pairs, encoded using Base64

http-auth-basic

HTTP Server from scratch in Rust

This project is a zero dependency single-threaded HTTP server made from scratch with headers and some file extensions support in Rust

HTTP Server from scratch in Rust

HTTP Digest Access Authentication for Rust

A (mostly) complete implementation of ITEF RFC2069, RFC2617 and RFC7616

HTTP Digest Access Authentication for Rust
Http

375

HTTP mocking for Rust!

Before upgrading, make sure to check out the rustfmt as a general code style

HTTP mocking for Rust!
Http

329

HTTP mocking to test Rust applications

wiremock provides HTTP mocking to perform black-box testing of Rust applications that

HTTP mocking to test Rust applications

HTTP Server with Rust

Rust http server from scratch

HTTP Server with Rust
Http

289

HTTP mocking library for Rust

Advanced verification and debugging support

HTTP mocking library for Rust

HTTP Mocking con httpmock

Este repositorio se corresponde con el código del

HTTP Mocking con httpmock
Facebook Instagram Twitter GitHub Dribbble
Privacy