elm / http

Make HTTP requests in Elm
https://package.elm-lang.org/packages/elm/http/latest
BSD 3-Clause "New" or "Revised" License
155 stars 46 forks source link

Are Task requests rare? #50

Closed jinjor closed 5 years ago

jinjor commented 5 years ago

(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.

module Api.Request exposing (..)

getFoo : String -> Task Http.Error Foo
postFoo : Foo -> Task Http.Error Foo
...

The reason of having Task based API is that we often have to combine requests.

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:

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.

jinjor commented 5 years ago

Okay, I asked for feedback in discourse. Very interested to see how it goes! https://discourse.elm-lang.org/t/using-task-to-send-http-requests/2696