Skip to content

thatmagicalcat/crane

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

A simple and fast web server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages