craweb

Crates.iocraweb
lib.rscraweb
version0.3.0
sourcesrc
created_at2022-07-11 11:05:19.439162
updated_at2022-07-25 15:11:41.781093
descriptionMultithreaded asynchronous web server, written in Rust.
homepage
repositoryhttps://gitlab.com/Pelfox/craweb
max_upload_size
id623712
size17,729
Aleksey Demchenkov (Pelfox)

documentation

README

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.

Commit count: 0

cargo fmt