1 unstable release

0.0.1 Jan 19, 2020

#390 in #futures

MIT license

595KB
14K SLoC

Scrappy - the best web-framework for Rust

crates.io Build Status codecov

Purpose

The purpose of this library is to be your web framework for Rust.

The priorities are to provide an ergonomic, fast, safe, well-tested, and well-documented experience.

This is a hard fork of Actix-Web & Actix & all sub-packages


lib.rs:

User sessions.

scrappy provides a general solution for session management. Session middlewares could provide different implementations which could be accessed via general session api.

By default, only cookie session backend is implemented. Other backend implementations can be added.

In general, you insert a session middleware and initialize it , such as a CookieSessionBackend. To access session data, Session extractor must be used. Session extractor allows us to get or set session data.

use scrappy::{web, App, HttpServer, HttpResponse, Error};
use scrappy_session::{Session, CookieSession};

fn index(session: Session) -> Result<&'static str, Error> {
    // access session data
    if let Some(count) = session.get::<i32>("counter")? {
        println!("SESSION value: {}", count);
        session.set("counter", count+1)?;
    } else {
        session.set("counter", 1)?;
    }

    Ok("Welcome!")
}

#[scrappy_rt::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(
        || App::new().wrap(
              CookieSession::signed(&[0; 32]) // <- create cookie based session middleware
                    .secure(false)
             )
            .service(web::resource("/").to(|| HttpResponse::Ok())))
        .bind("127.0.0.1:59880")?
        .run()
        .await
}

Dependencies

~24MB
~544K SLoC

$^