#web-server #web-framework #non-intrusive

zvezda

Simple, fast, lightweight and non-intrusive web library

4 releases

0.1.4 Jun 6, 2023
0.1.3 Mar 30, 2023
0.1.2 Feb 23, 2023
0.1.1 Feb 23, 2023

#752 in HTTP server

26 downloads per month

BSD-2-Clause-Patent

10KB
134 lines

Zvezda

A web library, not a web framework

Why?

One of my big gripes with a lot of these existing web server implementations for rust is that they are all big! You need to look through documentation for 15 minutes and 100 lines of boilerplate to even know what your doing! Thats why I began work on Zvezda.


Running included samples

  1. Clone this repository: https://gitlab.com/inzig0/zvezda.git
  2. cd into the project folder
  3. Run one of the examples:
    • Barebones web server: cargo run --example hello
    • Basic ping-pong web server: cargo run --example echo
    • Simple boilerplate web server: cargo run --example html
    • JSON usage example: cargo run --example json

Including this library in your project

Add this line to your Cargo.toml :

...
[dependencies]
zvezda = "0.1.1"
// OR if you want the git version,
zvezda = { git = "https://gitlab.com/inzig0/zvezda.git" }
...

lib.rs:

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();
            }
        }
    }
}

No runtime deps