My first Rust program - yet another client for a JSON API

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).

1 Like