Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/co-rs/mco-http
mco based http server and client
https://github.com/co-rs/mco-http
async http http-server httpclient
Last synced: about 2 months ago
JSON representation
mco based http server and client
- Host: GitHub
- URL: https://github.com/co-rs/mco-http
- Owner: co-rs
- License: apache-2.0
- Created: 2022-01-25T13:15:58.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-10T08:30:34.000Z (about 1 year ago)
- Last Synced: 2024-10-31T11:55:19.449Z (2 months ago)
- Topics: async, http, http-server, httpclient
- Language: Rust
- Homepage:
- Size: 797 KB
- Stars: 8
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mco-http
* HTTP framework based on Coroutine library [mco](https://github.com/co-rs/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
```rust
#[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
```rust
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();
}
```