8 releases

0.3.0 Jul 25, 2022
0.2.3 Jul 22, 2022
0.1.3 Jul 13, 2022

#987 in HTTP server

Download history 45/week @ 2024-02-21 15/week @ 2024-02-28

60 downloads per month

MIT license

17KB
295 lines

Craweb

Total downloads count Latest crate version

Multithreaded asynchronous web server, written in Rust. And it's really fast (we are handling one request in less than 1 second)!

Installation

You can install this crate using crates.io.

[dependencies]
craweb = "*" # Or you can replace version with specific ones.

Writing basic server

In order to start the server, you must do the following:

  1. Initialize the server in your main.rs file.
  2. Add at least one route.
  3. Bind the server to the specific IP address and port.

Here's an example (as well as in the example_server in the root repository):

use std::collections::HashMap;
use std::sync::Arc;

use craweb::{
    models::Response,
    server::Server,
};

#[tokio::main]
async fn main() {
    let mut server = Server::new(None, None, None);

    server.get("/", |_| {
        let mut headers = HashMap::new();
        headers.insert("Content-Type", "application/json");

        return Response {
            content: "{\"status\": \"Hello, World!\"}",
            status_code: 200,
            status_message: "OK",
            headers,
        };
    });

    Arc::new(server).bind("127.0.0.1:3000").await;
}

License

This crate is licensed under the MIT License. You can read the full license text here.

Dependencies

~4–11MB
~83K SLoC