Permalink
Browse files

make http request

  • Loading branch information...
maxhoffmann committed Jan 24, 2016
1 parent bc8aced commit f3aa112423dfdc1489d60b231747a3ce6471eca8
Showing with 26 additions and 1 deletion.
  1. +26 −1 App.elm
27 App.elm
@@ -2,7 +2,11 @@ module App where
import Signal exposing (..)
import Html exposing (..)
import Html.Events exposing (onClick)
import Effects exposing (Effects, Never)
import Http exposing (get)

This comment has been minimized.

@maxhoffmann

maxhoffmann Jan 24, 2016

Owner

small error: exposing (get) is not necessary here, as I use it via the namespace with Http.get

import Json.Decode as Json exposing ((:=))
import Task
-- MODEL
@@ -24,6 +28,8 @@ init =
type Action
= DoNothing
| RequestIP
| UpdateIP (Maybe String)
update: Action -> Model -> (Model, Effects Action)
update action model =
@@ -32,11 +38,30 @@ update action model =
DoNothing ->
(model, Effects.none)
RequestIP ->
(model, requestIP)
UpdateIP ip ->
(
{ model | ip = (Maybe.withDefault "No response" ip) },
Effects.none
)
-- VIEW
view : Address Action -> Model -> Html
view address model =
div [] [
button [] [ text "Get IP address" ],
button [ onClick address RequestIP ] [ text "Get IP address" ],
div [] [ text model.ip ]
]
--- Effects
requestIP : Effects Action
requestIP =
Http.get ("ip" := Json.string) "http://jsonip.com"
|> Task.toMaybe
|> Task.map UpdateIP
|> Effects.task

0 comments on commit f3aa112

Please sign in to comment.