page-turner
A generic abstraction of paginated APIs
In a nutshell
If you have a paginated request implement a page turner trait for this request on your client:
use *;
The page turner then provides stream-based APIs that allow data to be queried as if pagination does not exist:
use *;
use ;
async
Both cursor and non-cursor pagination patterns are supported and for the later
one you can enable a concurrent querying by implementing the RequestAhead
trait:
Now you can use pages_ahead/pages_ahead_unordered family of methods to
request multiple pages concurrently using a quite optimal sliding
window
request scheduling under the hood:
use *;
use TryStreamExt;
async
The example above schedules requests for 4 pages simultaneously and then issues a request as soon as you receive a response concurrently awaiting for 4 responses all the time while you're processing results.
v1.0.0 release
The v1.0.0 uses features like RPITIT stabilized in Rust 1.75, so MSRV for
v1.0.0 is 1.75.0. If you can't afford to upgrade to Rust 1.75 use 0.8.2
version of the crate. It's quite similar and supports Rust versions the
async_trait crate supports.
See docs for details about new supported features.
See CHANGELOG.md for full changes history.
Migration to v1.0.0 from older versions
There are several major breaking changes in v1.0.0, here are instructions how to quickly adopt them:
-
No more
#[async_trait]by default. Remove#[async_trait]from your page turner impls and everything should work. If you for some reason rely ondyn PageTurnerthen enable featuredynamicand usepage_turner::dynamic::prelude::*instead of thepage_turner::prelude::*. -
New page turners don't enforce you to return
Vec<PageItem>anymore, now you can return whatever you like(HashMapis a one example of a popular alternative). To quickly make your code compile retaining the old behavior replacetype PageItem = YourItem;withtype PageItems = Vec<YourItem>;. Note thatsinPageItems:) -
PageTurnerOutputwas renamed intoTurnedPageResultbut it is the same type alias so a simple global search&replace should do the trick. -
into_pages_aheadandinto_pages_ahead_unorderedmethods now require implementors to be clonable. Previously, they usedArcunder the hood, but now it's up to you. Most likely your clients are already cheaply clonable but if not then the quickest way to fixdoesn't implement Cloneerrors is to wrap your clients intoArclikeArc::new(client).into_pages_ahead(..).
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.