Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi.
Expect msg
is an opaque type and has a type parametermsg
. There are situations when amapExpect
function can be useful to map a message produced by expect. In fact such function is implemented already in kernel module.At the moment
Http
module exposes functions to transform requests toCmd msg
andTask x a
. Both of the types exposemap
function. However it's a higher level abstraction on top of Http request. Once you converted Http request to command or task there is no way to go back.On the other side it seems very harmless to expose
mapExpect
function to provide lower level manipulations with Http requests.Alternative solution is to build own abstraction around Http request and transform it to a request with
Expect msg
at the very end.My situation where it's useful.
(1) Let's say each request has some common logic around it. If the user is authenticated we send a request header with an authentication token to the server. Let's say we send few more common headers to the server.
One way to handle it is to drill the token and other common data to every place we'd like to make an Http request.
Another way is to make a middleware between Elm runtime and the place where we make an Http request so that all common headers added for each request.
(2) On each response from server we would like to do some common stuff. E.g. server invalidates a token and we want to logout the user. Or the server returns it's current time, so that we want to sync client time with server time, etc... The point is that there is a common logic for each response from the server.