Giter Site home page Giter Site logo

reywen-http's Introduction

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

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<ExampleData> for Option<Vec<u8>> {
    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::<Value>(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<u8>, 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(())
}

reywen-http's People

Contributors

toastxc avatar vloddot avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.