#python-requests

synchronous-server

Low level synchronous server

10 releases

0.1.12 Apr 2, 2024
0.1.11 Dec 19, 2023

#1513 in Network programming

MIT license

10KB
169 lines

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.

Dependencies

~2.5–8.5MB
~81K SLoC