Skip to content

Non-tokio runtime compatibility - #46

Open
jthacker wants to merge 1 commit into
mendess:masterfrom
jthacker:jmt/alternative-http-client
Open

Non-tokio runtime compatibility#46
jthacker wants to merge 1 commit into
mendess:masterfrom
jthacker:jmt/alternative-http-client

Conversation

@jthacker

@jthacker jthacker commented May 25, 2024

Copy link
Copy Markdown

Why?

Make scryfall-rs usable under non-tokio async runtimes.
Reqwest is only compatible with tokio. Surf is compatible with async-std, tokio, or any other standard futures compliant runtime.
seanmonstar/reqwest#719 (comment)

Known Issues

This will break backwards compatibility in the API. Specifically in regards to the removal of the ReqwestError variant.
It is not abstracted in HttpClientError as a string so going forward, any changes to the http client shouldn't have an impact on the public API.

Comment thread src/uri.rs
if status.is_success() {
Ok(response.body_json().await?)
} else {
Err(Error::HttpError(StatusCode::from(u16::from(status))))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does surf use http crate status code? If yes I think we should drop the httpstatus dependency as well

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surf uses http_types.
This would also create additional backwards incompatibility since it leaks out too in case that matters. Same group that created surf.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think we should take the opportunity of making a breaking change and think about other good changes. My understanding is that http is the most standard source of basic http types. httpstatus is definitely not it. Do you think http_types is a good idea to be the type we export out of this crate's error type?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the topic of making breaking changes, scryfall itself makes breaking changes all the time, so this crate has to make a lot of them as well. To be precise, wizards makes a lot of breaking changes 🤣

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't say I have a ton of experience with it. I think it is better quality than httpstatus but haven't done a thorough comparison either. From a quick survey, StatusCode in http-types and http looks pretty similar.

Options:

  • http-types - zero impedance mismatch with surf
  • http - most popular interface
  • u16 - Remove the public facing dep entirely as just return a u16, let the client decide if they want to "interpret" it by pulling it into their favorite StatusCode object. Prevents consumers from being pinned to a specific version of the library too.

I actually think the last option might be the best.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should go with the last option them. Makes sense to me

@mendess

mendess commented May 25, 2024

Copy link
Copy Markdown
Owner

Thanks for this PR, TIL about surf!

For my own learning, I'm curious about your motivation for this PR, I myself only use Tokio, tried async-std once but never really used, can you tell me some reasons for preferring async-std over Tokio?

@jthacker

Copy link
Copy Markdown
Author

@mendess The main motivation is to use this within a bevy app. It is not directly compatible with Tokio but uses it's own internal executor that is compatible with standard futures. Surf doesn't specifically rely on tokio or async-std but at least enables compatibility with either, in addition to any other executor that uses standard futures (such as in the case of bevy). I'm no expert in this but this is what I have concluded from my time boxed investigation.

@xremming

Copy link
Copy Markdown
Contributor

We could also make a larger refactoring to the API and add a Client to it which could then support arbitrary ways to make the API calls (and change the current methods for the API calls to construct the client with Client::default for example). This would easily add support for re-using the HTTP client and ways to customize re-tries and throttling.

@mendess

mendess commented May 27, 2024

Copy link
Copy Markdown
Owner

We could also make a larger refactoring to the API and add a Client to it which could then support arbitrary ways to make the API calls (and change the current methods for the API calls to construct the client with Client::default for example). This would easily add support for re-using the HTTP client and ways to customize re-tries and throttling.

I really like this idea. This was my first real rust project so it naturally misses some good ideas haha. Feel free to make a PR with this change! And thanks for the idea!

@xremming

Copy link
Copy Markdown
Contributor

I will see if I have the time and interest to work on it. No promises.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants