Crates.io | crane-webserver |
lib.rs | crane-webserver |
version | 0.1.6 |
source | src |
created_at | 2023-10-28 10:23:02.510442 |
updated_at | 2023-11-03 12:05:21.252972 |
description | A simple and fast webserver. |
homepage | |
repository | https://github.com/Pranjal-Patel/crane |
max_upload_size | |
id | 1016830 |
size | 49,964 |
A simple and fast webserver :)
In order to build a webserver, you need to add crane-webserver
as a dependency in your rust project by:
cargo add crane-webserver
Create an HTTP server that responds with a message.
use crane_webserver::*;
fn main() {
let server = WebServer::bind("127.0.0.1:8888", |path, query| {
match path.as_str() {
"/" => default_route_fn(query),
_ => ResponseBuilder::new().build(),
}
}).unwrap()
server.start();
}
fn root() -> Response {
ResponseBuilder::new()
.status(HttpStatus::OK)
.header("Content-Type", "text/plain")
.body("Hello, World!")
.build()
}
$ curl localhost:8888/
Hello, World!