Reputation: 2674
I want to do something very un-functional and make an HTTP request in elm without processing any kind of response. Basically something like this:
testView : Html Msg
testView =
div [] [
button [onClick TestAction] [text "Test Action"]
]
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
...
TestAction ->
( model, testActionCmd )
...
import Http
import HttpBuilder exposing (..)
...
testActionCmd : Cmd Msg
testActionCmd =
( "http://localhost:4000/fakeurl" )
|> get -- this is a side effect; unrelated to the Msg below
Cmd.none -- this is what I want to return
Is there a way to do something like this in Elm?
Upvotes: 0
Views: 119
Reputation: 9885
In short, no, you won't be able to do that (not without writing your own effect manager or using ports).
The "problem" is that the Http
module allows you to create a Task
which you then need to convert into a Cmd
to perform the task. But to go from a Task
to a Cmd
you need to provide a Msg
. See http://package.elm-lang.org/packages/elm-lang/core/5.1.1/Task
So what you'll need to do is create one of those Noop messages.
Upvotes: 5