Typesafe ApiClient Runtime Injection for @Effect-Atom and HttpApiBuilder
I'm trying to isolate my features from my main app, while still letting the main app have its own AppApi etc.
So I want to be able to make ApiClients and HttpApiBuilders that instead of taking the global AppApi, take in a smaller Api, which can be used in multiple apps (including the apps prefixes)
Naturally, an AppApi will have a prefix, or some groups under a prefix.
With Effect-Atom, if I have an Atom like (taken from the effect-atom readme docs)
This will always post to ${baseUrl}/count/increment
I want to isolate my CountClient from the app runtime and api so that I can use it in multiple apps, because right now, you have to make the runtime either with Atom.context or with something like AtomHttpApi.Tag.
However, I want to be able to run my CountClient by itself independent of the app, AND be able to inject the app api, and have it use that instead.
I've unsuccesfully tried... - Making an ApiClient Factory -Analyzing the HttpApi Metadata with HttpApi.Reflect to see if two different Api's implement the same group (this worked! but doesnt help swap out the atomruntime) -Having an AtomService that depends on inputting an HttpApi that has the same endpoints (recursivley to account for app prefixing) -Literally using React useEffect to switch between two different runtimes at runtime (obviously this is a bad idea)
Other things I want to try but am not smart enough to yet... - Config module with Effect.Config? - A managedRuntime where by default, it would post $[baseUrl}/count/increment, but if the managedRuntime was provided an ApiLayer like AppApi, it would then post to ${AppApi'sBaseUrl}/{AppApiPrefixesBeforeCount}/Count/Increment -Storing the Prefix data inside an atom of the Atom Registry and providing that based on the prefix if found analyzing the AppApi to the api its using