mco-http

Crates.iomco-http
lib.rsmco-http
version0.1.32
sourcesrc
created_at2022-02-16 07:29:32.709188
updated_at2023-12-08 14:05:01.015434
descriptionA modern HTTP library.
homepagehttps://github.com/co-rs
repositoryhttps://github.com/co-rs/mco-http.git
max_upload_size
id533135
size622,477
zxj (zhuxiujia)

documentation

README

mco-http

  • HTTP framework based on Coroutine library mco, Original code fork from Hyper,We improved the underlying logic
  • Light weight, high performance
  • support http/https server (see examples)
  • support http/https client (see examples)
  • support route
  • support Interceptor/middleware

example-server

#[deny(unused_variables)]
extern crate mco_http;

use mco_http::route::Route;
use mco_http::server::{Request, Response};

fn hello(req: Request, res: Response) {
    res.send(b"Hello World!");
}

fn main() {
    let mut route = Route::new();
    route.handle_fn("/", |req: Request, res: Response| {
        res.send(b"Hello World!");
    });
    route.handle_fn("/js", |req: Request, res: Response| {
        res.send("{\"name\":\"joe\"}".as_bytes());
    });
    route.handle_fn("/fn", hello);
    let _listening = mco_http::Server::http("0.0.0.0:3000").unwrap()
        .handle(hello);
    println!("Listening on http://127.0.0.1:3000");
}

example-client

extern crate mco_http;

use std::io;
use mco_http::Client;
use mco_http::header::Connection;

fn main() {
    let mut url = "http://www.baidu.com".to_string();

    let client = Client::new();

    let mut res = client.get(&url)
        .header(Connection::close())
        .send().unwrap();

    println!("Response: {}", res.status);
    println!("Headers:\n{}", res.headers);
    io::copy(&mut res, &mut io::stdout()).unwrap();
}
Commit count: 310

cargo fmt