(I don't know this is the right place to ask this question. Please redirect to discourse if needed.)
The doc comment on Http.task says:
Just like request, but it creates a Task. This makes it possible to pair your HTTP request with Time.now if you need timestamps for some reason. This should be quite rare.
However, I don't get why using tasks should be rare. (Or, does "This" point the use of Time.now?) So, some notes about the thoughts behind it would help.
Context
We have many API requests in the codebase at work. Like this.
The reason of having Task based API is that we often have to combine requests.
Task.map2 or Task3 to combine multiple requests to initiate each page
Ideally, this should be done in parallel.
Task.andThen to chain requests
For example, getFoo fooId |> Task.andThen (\foo -> getBar foo.barId)
All the functions return Task by default so we can avoid calling toTask so often (which happened when I used Request based API in 1.0.0).
I guess the answer of my question is something like:
HTTP requests should not be sent very frequently (chatty API is an anti pattern)
UI should show each data respectively (object-based UI design)
Server should give optimized API for each page
They might be true, but our development cannot always do things right. Seeing labels like "should not" or "rare" is a kind of fear when we are deeply depending on the feature, because it sometimes means "this feature will be removed soon".
Edit:
Another context: I'm writing an explanation of Task in my book and it says "Task is useful to chain HTTP requests" with some examples.
(I don't know this is the right place to ask this question. Please redirect to discourse if needed.)
The doc comment on
Http.task
says:However, I don't get why using tasks should be rare. (Or, does "This" point the use of
Time.now
?) So, some notes about the thoughts behind it would help.Context
We have many API requests in the codebase at work. Like this.
The reason of having
Task
based API is that we often have to combine requests.Task.map2
orTask3
to combine multiple requests to initiate each pageTask.andThen
to chain requestsgetFoo fooId |> Task.andThen (\foo -> getBar foo.barId)
All the functions return
Task
by default so we can avoid callingtoTask
so often (which happened when I usedRequest
based API in 1.0.0).I guess the answer of my question is something like:
They might be true, but our development cannot always do things right. Seeing labels like "should not" or "rare" is a kind of fear when we are deeply depending on the feature, because it sometimes means "this feature will be removed soon".
Edit: Another context: I'm writing an explanation of Task in my book and it says "Task is useful to chain HTTP requests" with some examples.