I'm going through the Rust book and while at it, trying to build an SDK for a JSON web API. I'm looking for general advice or anything I could improve and make more idiomatic. Anything that comes to mind would be really helpful!
Thanks in advance
The "how to properly wrap an HTTP API" question comes up from time to time.
I don't recommend mashing all endpoints together in one gigantic
enum as they haven't got much to do with one another, and you will end up writing a lot of boilerplate code too.
You should probably start with the design I outlined here, ie., use generics and Request/Response traits instead of concrete types. Then each concrete request/response type can deal with defining its own endpoint, method, query string, headers, etc. Furthermore, your wrapper methods will be correctly typed (every request will have an associated response type).
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.