2 releases

0.0.2 Jan 19, 2020
0.0.1 Jan 19, 2020

#994 in HTTP server


Used in 6 crates

MIT license

1.5MB
38K SLoC

Scrappy - the best web-framework for Rust

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:

scrappy web is a small, pragmatic, and extremely fast web framework for Rust.

use scrappy::{web, App, Responder, HttpServer};

async fn index(info: web::Path<(String, u32)>) -> impl Responder {
    format!("Hello {}! id:{}", info.0, info.1)
}

#[scrappy_rt::main]
async fn main() -> std::io::Result<()> {
    HttpServer::new(|| App::new().service(
        web::resource("/{name}/{id}/index.html").to(index))
    )
        .bind("127.0.0.1:8080")?
        .run()
        .await
}

Documentation & community resources

Besides the API documentation (which you are currently looking at!), several other resources are available:

To get started navigating the API documentation you may want to consider looking at the following pages:

  • App: This struct represents an scrappy-web application and is used to configure routes and other common settings.

  • HttpServer: This struct represents an HTTP server instance and is used to instantiate and configure servers.

  • web: This module provides essential helper functions and types for application registration.

  • HttpRequest and HttpResponse: These structs represent HTTP requests and responses and expose various methods for inspecting, creating and otherwise utilizing them.

Features

  • Supported HTTP/1.x and HTTP/2.0 protocols
  • Streaming and pipelining
  • Keep-alive and slow requests handling
  • WebSockets server/client
  • Transparent content compression/decompression (br, gzip, deflate)
  • Configurable request routing
  • Multipart streams
  • SSL support with OpenSSL or native-tls
  • Middlewares (Logger, Session, CORS, DefaultHeaders)
  • Supports scrappy actor framework
  • Supported Rust version: 1.39 or later

Package feature

  • client - enables http client (default enabled)
  • compress - enables content encoding compression support (default enabled)
  • openssl - enables ssl support via openssl crate, supports http/2
  • rustls - enables ssl support via rustls crate, supports http/2
  • secure-cookies - enables secure cookies support, includes ring crate as dependency The scrappy-web prelude for library developers

The purpose of this module is to alleviate imports of many common scrappy traits by adding a glob import to the top of scrappy heavy modules:

use scrappy::dev::*;

An HTTP Client

use scrappy::client::Client;

#[scrappy_rt::main]
async fn main() {
   let mut client = Client::default();

   // Create request builder and send request
   let response = client.get("http://www.rust-lang.org")
      .header("User-Agent", "scrappy-web")
      .send().await;                      // <- Send http request

   println!("Response: {:?}", response);
}

Dependencies

~32MB
~656K SLoC