Skip to content

burdockcascade/teapot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TEAPOT

MIT licensed GHA Build Status

Status

This project is in early development and is not yet ready for production use.

Example

fn main() {
    
    info!("Starting teapot server example...");
    
    let my_teapot = Arc::new(Mutex::new(MyHandler { counter: 0 }));
    
    HttpServer::builder()
        .address("127.0.0.1")
        .port(80)
        .route(RouteBuilder::http()
            .get("/teapot")
            .handler(my_teapot.clone())
            .build()
            .expect("valid route"))
        .start();

}

struct MyHandler {
    counter: u16
}

impl RouteHandler for MyHandler {
    fn on_request(&mut self, _request: &HttpServerRequest) -> HttpServerResponse {
        
        self.counter += 1;
        let message = format!("Serving cup number {}", self.counter);
        
        HttpServerResponse::builder()
            .status(StatusCode::OK)
            .header("Content-Type", "text/plain")
            .body(Body::text(message))
            .build()
    }
}

License

Licensed under the MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

About

A simple and modern web framework for rust

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages