8 releases
0.3.0 | Jul 25, 2022 |
---|---|
0.2.3 | Jul 22, 2022 |
0.1.3 | Jul 13, 2022 |
#970 in HTTP server
53 downloads per month
17KB
295 lines
Craweb
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:
- Initialize the server in your
main.rs
file. - Add at least one route.
- 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
~3.5–10MB
~84K SLoC