crane-webserver

Crates.iocrane-webserver
lib.rscrane-webserver
version0.1.6
sourcesrc
created_at2023-10-28 10:23:02.510442
updated_at2023-11-03 12:05:21.252972
descriptionA simple and fast webserver.
homepage
repositoryhttps://github.com/Pranjal-Patel/crane
max_upload_size
id1016830
size49,964
(thatmagicalcat)

documentation

README

crane

Rust

A simple and fast webserver :)

Getting started

In order to build a webserver, you need to add crane-webserver as a dependency in your rust project by:

cargo add crane-webserver

Examples

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!
Commit count: 29

cargo fmt