Skip to content

Zodey-hub/tiny-http-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tiny-http-server

tiny-http-server is a simple blocking http server crate.

Example usage:

use std::net::Ipv4Addr;

use tiny_http_server::{
    http::{Response, StatusCode},
    server::Server,
};

const ADDRESS: (Ipv4Addr, u16) = (Ipv4Addr::UNSPECIFIED, 5000);

fn main() {
    let server = Server::bind(ADDRESS).unwrap();

    let _ = server.run(|req| {
        let response = match req.uri().path() {
            "/" => Response::builder()
                .status(StatusCode::OK)
                .header("Content-Type", "text/plain")
                .body("Hello World!".to_string())
                .unwrap(),

            _ => Response::builder()
                .status(StatusCode::NOT_FOUND)
                .body("404 Not Found".to_string())
                .unwrap(),
        };

        response
    });
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages