Giter Club home page Giter Club logo

Comments (1)

tonymushah avatar tonymushah commented on May 24, 2024

Hello there!

Firstly, Thank you for posting this interesting issue.

Secondly, I apologize for not responding you sooner,
I have a lot of projects behind this and I didn't have the time on focusing on this issue.

Thirdly, Your proposition for adding rate limiting handling is interesting,
but adding field on mangadex_api_schema::ApiData would be technical challenge for me.

There is around 30 endpoints that respond with these headers, and each of them have a different response type.
I know that some of them respond with the : mangadex_api_schema::ApiData,
but for the GET /at-home/server/{id}, his response type is mangadex_api_schema::v5::AtHomeServer.

After re factoring all of the SDK for the new syntax, I come up with an idea that should be 'easy' to implement and noticeable in your development.

We added these struct :

/// This `RateLimit` struct contains all the data needed for rate limit handling
/// It can be parsed via a [`reqwest::Response`] or [`reqwest::header::HeaderMap`]
#[derive(Serialize, Debug)]
#[cfg_attr(feature = "non_exhaustive", non_exhaustive)]
pub struct RateLimit {
    /// value from `x-ratelimit-limit` header
    pub limit: u32,
    /// value from `x-ratelimit-remaining` header
    pub remaining: u32,
    /// value from `x-ratelimit-retry-after` header
    /// It's normally an [`i64`] [(Unix timestamp)](https://www.unixtimestamp.com/) 
    /// but can be parsed as a [`crate::MangaDexDateTime`]
    pub retry_after: MangaDexDateTime,
}
/// This struct is used for rate limited endpoint
/// `rate_limit` is for the rate limit metadata
/// `body` is the response data
pub struct Limited<T> {
    pub rate_limit: RateLimit,
    pub body: T,
}

The RateLimit struct is for the rate limit metadata header.
And the Limited<T> is for handling the metadata.

I know that it might be a strange solution but it's the only one that i come up with.

You can lookup to this linked pull request #87 to see the work progess

from mangadex-api.

Related Issues (20)

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.