Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/toastxc/reywen-http
Easy to use async HTTP client library based on Hyper
https://github.com/toastxc/reywen-http
Last synced: 15 days ago
JSON representation
Easy to use async HTTP client library based on Hyper
- Host: GitHub
- URL: https://github.com/toastxc/reywen-http
- Owner: toastxc
- Created: 2023-05-10T07:08:41.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-10T04:28:01.000Z (11 months ago)
- Last Synced: 2023-12-10T05:21:23.284Z (11 months ago)
- Language: Rust
- Homepage:
- Size: 95.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Reywen-HTTP
### Why another HTTP lib?
Originally I maintained my own HTTP library within a project for Revolt.chat, but it became too large and is now in it's own repository. That said the library can be easily used by anyone for any API!### Features
- built-in serde support
- can use a variety of HTTP engines
- WASM support
- Tokio async### Example Using Hypixel API
As shown below the library can be used without much prior setup or configuration, and runs asynchronously.This example uses Hyper as its backend, however there are many different HTTP engines available for use. All of them implement the same Request/ReqRaw syntax
```rust
use crate::engines::hyper::{Error, Hyper};
use hyper::Method;
use serde::{Deserialize, Serialize};
use serde_json::Value;#[derive(Serialize, Debug, Deserialize, Default)]
pub struct ExampleData {
field1: String,
}impl From for Option> {
fn from(value: ExampleData) -> Self {
todo!()
}
}
pub async fn hypixel_example() -> Result<(), Error> {
// define client, fields within the client declaration are global and will apply to all requests
// unless overwritten
let client = Hyper::new().set_url("https://api.hypixel.net");// request requires serde and will deserialize data based on the T input type
println!(
"{}",
client
.request::(Method::GET, "/skyblock/bazaar", None)
.await?
);// request raw will return a byte array for as the response
client
.request_raw(Method::GET, "/skyblock/bazaar", None)
.await?;// data sent over request or request_raw must be of type Vec, String or any type that can be
// converted to those types
client
.clone()
.set_url("example.com")
.request_raw(Method::POST, "", ExampleData::default())
.await?;
Ok(())
}
```