Comments (9)
I'd be willing to do it, but I'm not sure I should. My inspiration for the abstraction came from the oauth2 crate, watching museun code multiple client abstractions for twitchchat, and the implementation in http-client. Currently there is to my knowledge one attempt at doing client abstractions for http, and that's http-client
, but, that one doesn't exactly do what I'm doing. There is also a stale api
crate which could be promising for the "request" parth, but it could do with some more attention.
http-client
is nice, but it does not use http (for some good reasons), you could use that for client abstraction, but you'd need to use http-types.
There is one problem also. If I define these implementations in another crate for usage by other crates, making a default impl on create_request
and others would be impossible for those crates. I guess I could make it work, not sure how.
Instead, I think it'd be better to expose the framework by usage of proc macros. I'm not sure I like the idea though.
So, I think, best course of action is a crate that enables you to do basically the following
use api_client::ApiClient;
#[derive(ApiClient)] /// Adds relevant methods
#[api(mod = "helix_request")]
struct<'client> HelixClient<'client, C> where C: api_client::ApiClient<'client> {
#[api(client)]
client: C,
pub custom_field: (),
}
pub mod helix_request {
pub trait RequestGet: api_client::Request {
type Body: serde::Serialize;
fn create_request(fields...) -> Result<api_client::Request, MyCreationError> {...}
fn parse_response<'a>(response: api_client::Response<'a>) -> Result<<Self as Request>::Response<'a>, MyResponseError<'a>> {...}
}
//... etc etc
}
pub mod foo_api_thing {
pub struct FooRequest {
pub foo: String,
}
impl api_client::Request for Foo {
// something here
}
impl crate::helix_request::RequestGet for FooRequest {
// something here
}
}
I'm not sure it's possible, but it'd be neat I think.
from twitch_api.
@Emilgardis I created a temporary private repository from the effort to outsource the implementation into an external crate and invited you to collaborate. Would you take a look?
from twitch_api.
As an addition: I think what could be done as well then is to create a macro
which is generating the request implementations for different endpoints or other tooling to generate the request implementation from an OpenAPI
file.
from twitch_api.
Good idea, yeah that looks nice. I already ported my code for the backend to yours and it works out nicely. Only thing I had to change is the parse_response
part as I have a pretty unstable API and need to parse directly into serde_json::Value
and not InnerResponse
or alike. But yes, absolute lovely stuff, great work. :)
from twitch_api.
Awesome! Could I perhaps see the source for that? No worries if its not publicly available
from twitch_api.
Awesome! Could I perhaps see the source for that? No worries if its not publicly available
Sure, but beware of the code quality, I'm not a professional Rust programmer :D
(and the crates are also not properly documented for the use case as I did the refactoring to the client/request abstraction just the last days)
https://github.com/transparencies/transparencies-backend-rs/tree/main/crates
from twitch_api.
Small cross-reference
Someone posted this article on reddit that reminded me of this issue:
https://plume.benboeckel.net/~/JustAnotherBlog/designing-rust-bindings-for-rest-ap-is
The corresponding reddit thread with discussions is this one:
https://www.reddit.com/r/rust/comments/r3txac/questions_on_ergonomically_wrapping_a_rest_api/
The corresponding discussion about factoring out the needed part of rust-gitlab
into an API-agnostic crate is here:
https://gitlab.kitware.com/utils/rust-gitlab/-/issues/56
from twitch_api.
Yeah i saw that! Still havent given it a proper look yet. This issue is still on my todo list though 😅
from twitch_api.
Yeah i saw that! Still havent given it a proper look yet. This issue is still on my todo list though 😅
No stress, but I do like your design really much, so I recommend it. (: rust-gitlab
has a slightly different design that is also nice. I haven't looked so deep into it, that I could say much more about it. But I would love to bring this effort forward, that there might be some kind of well-designed api-agnostic REST-API crate for the community. And I think it's always good to work together. :)
from twitch_api.
Related Issues (20)
- RUSTSEC-2021-0141: dotenv is Unmaintained
- Parsing event callback failed with "UnimplementedEvent" on mock API HOT 4
- Trait to turn paginated APIs into async streams HOT 1
- Make user agent more distinct
- Impossible to use requests / body with DeserializeOwned HOT 5
- EventSub Over WebSocket HOT 3
- Why can't I put multiple broadcaster_id in GetChannelInformationRequest? HOT 2
- Games: Get Games and Get Top Games IGDB Field
- Help appreciated (get_followed_streams) HOT 2
- Getting a backtrace with a specific broadcaster id 418158680 HOT 2
- introduce `beta` feature for public betas instead of `unsupported`
- Make `helix::client::custom` first-class
- another bug while decoding teaminfo HOT 4
- Add way to mock responses
- Investigate querying twitch docs HOT 1
- sprinkle more must_use on all structs
- Bors deprecation - remaining
- Clarify how or make it easier to pass in collections that are T: Iterator<Item=D> in builder functions for helix requests HOT 4
- Create a tower rate limiter for helix which respects twitch headers
- use `async fn` and return-position `impl Trait` in trait HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from twitch_api.