synchronous-server

Crates.iosynchronous-server
lib.rssynchronous-server
version0.1.12
sourcesrc
created_at2023-12-12 12:05:24.216594
updated_at2024-04-02 05:23:15.223472
descriptionLow level synchronous server
homepage
repositoryhttps://github.com/kolserdav/synchronous-server
max_upload_size
id1066303
size19,373
Sergei Kol'miller (kolserdav)

documentation

README

synchronous-server

License

This is a Rust crate called synchronous-server, designed to provide reliable and efficient access services for your well-needed use cases. Our crate is built with synchronous communication in mind, ensuring that all requests are handled sequentially and without any asynchronous overhead.

Features

  • Synchronous communication for reliable and predictable behavior
  • Customizable request and response handling logic

Getting Started

To use this crate, you'll need Rust and Cargo installed. Then, follow these steps:

  1. Install synchronous-server:
cargo add synchronous-server
  1. Import the crate in your Rust module:
use synchronous_server::listen;
  1. Create a new Server instance with the request handler:
use std::io::Result;
use synchronous_server::{
    http::{
        headers::{Header, Headers},
        status::Status,
}, listen
};

pub fn main() -> Result<()> {
    let res = listen("0.0.0.0:4001", |d| {
        println!("{:?}", d);

        let result = "hello world".to_string();
        let code = 200;
        let headers = Headers::new_request(
            Status::new(code).to_full_string().as_str(),
            vec![
                Header {
                    name: "Content-Type".to_string(),
                    value: "text/plain".to_string(),
                },
                Header {
                    name: "Custom-Header".to_string(),
                    value: "Hello World!".to_string(),
                },
            ],
        );

        Ok((result, code, headers))
    });
    if let Err(err) = res {
        println!("Failed to listen server: {:?}", err);
    }

    Ok(())
}

Versioning

This package follows the Semantic Versioning (SemVer) scheme. See the CHANGELOG for release history.

Commit count: 36

cargo fmt