Making a REST call from Elm and geting back the results is quite a 
complicated process.

1. Set up a Msg that the UI can trigger the request from.
2. Write a Task to perform the request.
3. In the update function turn that into a Cmd to make the request using 
Task.perform.
4. Set up Msgs to handle the ok and error responses, or maybe just one Msg 
to handle both as a Result.
5. Deal with errors in some way.
6. Deal with the response by updating the model approriately.

I am wondering if all of this can be wrapped up in a more convenient 
interface that the consumer of a REST service can make use of in a simpler 
manner.

At the moment I am thinking:

Some convenience functions for triggering the various REST calls:

myExamplePost : SomeData -> ()

A convenience function that helps with lifting the 'update' function of the 
REST service within the update function of whatever module is making use of 
it. This will take as args:

- A function to extract from the model whatever part of the model is 
appropriate for updating when results are received.
- A record containing callback functions that will be invoked with results, 
e.g.

type alias Callbacks model msg =
    { myExampleGet : SomeData -> model -> Cmd msg
    , ...
    }

Often they will return Cmd.none, but that is put there in case other 
commands need to be chained.

Then the consumer of a REST service really just has to provide a set of 
callbacks, and has a convenient set of functions to help integrate the 
service, and to initiate requests. There will also need to be some 
callbacks for handling errors, not sure yet on the details of those.

I may be a bit approximate with the details above, but does this sound 
doable/reasonable? Has anyone done something along these lines already?

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to