Replies: 1 comment
-
Sorry I've been meaning to circle back here for a while and leave my thoughts. This is mostly just an abstract braindump. I'm really interested to hear what others think in this space and work towards some concrete recommendations! For high-level APIs I'm not sure what we could recommend in the general sense. If the API you're providing a client for has a proper hypermedia focus like GitHub then the methods you expose to build requests might make heavy use of composable builders (I think AsyncI think supporting async through Just offering an async client and providing a synchronous shim that calls I've previously offered a single client and used a generic parameter to offer different implementations of certain functions depending on whether it's sync or async. I wouldn't recommend this approach. It means some code can be shared if that client is threaded through a lot of request builders that have a lot of methods, but it's very complicated, and makes the crate docs much harder to follow. I would prefer to just be able to use a thin synchronous shim (or an async-only client) and let the fact that your sync code won't be running on the proposed default
If we could just expect users to
Error managementThe approach I've started taking is to have two classes of error:
In the first case, having an ergonomic way to interrogate the error to know what happened is important. In the other cases, having enough detail that can be logged and used to diagnose issues is important. I feel like a black-box with methods like |
Beta Was this translation helpful? Give feedback.
-
Let's recommend an idiomatic way to structure a Rust crate that provides an interface for an external JSON server (or similar), such as
wdsapi
for the IBM Watson Discovery Service orgithub-rs
for GitHub's API. Lots of crates already do this and each one has had to reinvent how to design the top-level API, how to expose the error when a request fails, how to support asynchronous requests, etc.I think this may work well as part of a broader guideline that recommends crates to look to for guidance on structuring crates for similar tasks. There is some overlap with the objectives of the Rust Cookbook, but that one is more for transferable tasks (unzip an archive, generate a random number) and this would be for cases where the entire structure of the crate is transferable (client for a REST API, FFI bindings for a native library).
@bruceadams -- thanks for the suggestions!
Beta Was this translation helpful? Give feedback.
All reactions