Crate zvezda

source ·
Expand description

Zvezda

Zvezda is a fast and lightweight web library, designed to provide HTML capability to your website. It is not like Warp or Rocket, which are designed to provide a framework to work off of, but instead to add a non-intrusive HTML backend implementation to your project.


Hello World Example

use std::net::TcpListener;
use std::io::Read;
use zvezda::Connection;
 
fn main() {
 
 
    let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
 
 
    for stream in listener.incoming() {
        let mut stream = stream.unwrap();
        let mut buf = [0; 1536];
 
        stream.read(&mut buf).unwrap();
 
        let packet = String::from_utf8_lossy(&buf);
 
 
        let mut handle = Connection::parse(packet.to_string(), stream);
 
        let path = handle.path_as_str();
        match path {
            "/" => {
                handle.write_html("200 OK", String::from("Hello World!")).unwrap();
            },
            _ => {
                handle.write_res("404 NOT FOUND").unwrap();
            }
        }
    }
}

Structs

Enums

  • The enumerator used to describe the HTTP request type