I'm just curious how everybody approaches their API service layer in 
complex applications.

Right now, I have a shared API module that I call from various 
elements/pages/components/children... in a pretty flat architecture. That 
module abstracts out the common request composition, etc.

What I want is to also have that module (or some shared abstraction) that
1. extracts an incoming response header
2. injects an outgoing request header

Let's say that every response includes a dynamic "token" header value, and 
every request needs to return that token in the headers. This directly 
analogous to the need to let http errors "bubble up to the root," which was 
discussed elsewhere, but not effectively resolved.

Right now I have an Api.sendJson call that returns a task, then I convert 
it to a command with local messages. But ideally those local messages are 
handling the error, or else the locally relevant model. Looking only to the 
successful response, mixing the returned data with the updated value 
extracted from the header, and doing it at every api call site, seems 
inefficient and clunky. I think I might be missing something obvious. Could 
anybody recommend an elegant solution to having a common service module 
that could wrap the http calls in both directions (requests and responses 
... a la middleware) cleanly? Any help would be greatly appreciated.

You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to