Crate rsweb

source ·
Expand description

rsweb

library for interacting with the http protocol and creating a multithreaded web server

To create a simple server just use the following code:


use rsweb::resource::ResourceLoader;
use rsweb::route::Router;
use rsweb::server::Server;
use rsweb::config::Config;

let conf = Config {http: None, ssl: None}; // just a config so this example works. In reality you would load a config
let mut server = Server::new(
    10, // number of threads
    ResourceLoader::new(10, ".".to_string(), true), // create a new resource loader with capacity 10
    // and caching enabled
    Router::new(), // create a new router with index at index.html
    8080, // port
    std::net::IpAddr::V4(std::net::Ipv4Addr::new(127,0,0,1)), // ip (localhost in this case)
    conf,
);

rsweb also supports ssl. To create a simple server that uses ssl use:

use rsweb::resource::ResourceLoader;
use rsweb::route::Router;
use rsweb::ssl::SSLServer;
use rsweb::config::Config;

let conf = Config {http: None, ssl: None}; // just a config so this example works.

let mut server = SSLServer::new(
    10, // number of threads
    ResourceLoader::new(10, ".".to_string(), true), // create a new resource loader with capacity 10 and caching enabled
    Router::new(), // create a new router with index at index.html
    8080, // port
    std::net::IpAddr::V4(std::net::Ipv4Addr::new(127,0,0,1)), // ip (localhost in this case)
    String::from("key.pem"), // private key file
    String::from("certs.pem"), // certificate chain file
    conf,
);

Re-exports

Modules

  • the cli of rsweb
  • the configuration reading functionality of rsweb
  • a dynamic buffer implementation used to read from streams
  • errors for rsweb
  • HTTP
  • logging functions for rsweb
  • resource handler and cache storage
  • router for requests
  • basic HTTP server implementation
  • basic HTTPS server implementation
  • Threadpool implementation included in the logs produced by log

Macros

Constants