2 releases

0.1.32 Dec 8, 2023
0.1.31 Dec 7, 2023
0.1.23 Mar 3, 2022
0.1.19 Feb 19, 2022

#153 in HTTP client

Download history 14/week @ 2024-07-01 63/week @ 2024-07-29 2/week @ 2024-08-26 61/week @ 2024-09-23

62 downloads per month
Used in mco-http-rustls

MIT/Apache

610KB
12K SLoC

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

Dependencies

~7–35MB
~538K SLoC