Created
May 24, 2016 17:53
-
-
Save szabba/53b6ff489a2de0b902efa91742a56564 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Html exposing (Html) | |
import Html.App as App | |
import Http | |
import Task exposing (Task) | |
main : Program Never | |
main = | |
App.program | |
{ init = init | |
, update = update | |
, view = view | |
, subscriptions = always Sub.none | |
} | |
-- MODEL | |
type alias Model = | |
String | |
init : (Model, Cmd Msg) | |
init = | |
( "" | |
, { url = "http://elm-lang.org/try" } | |
|> sendRequest | |
|> Task.perform (always Nothing) identity | |
) | |
-- MODEL | |
type alias Msg = | |
Maybe String | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
( msg |> Maybe.withDefault model | |
, Cmd.none | |
) | |
-- VIEW | |
view : Model -> Html Msg | |
view = | |
Html.text | |
-- HELPERS | |
sendRequest : { url : String } -> Task Http.RawError (Maybe String) | |
sendRequest { url }= | |
{ verb = "GET" | |
, headers = [] | |
, url = url | |
, body = Http.empty | |
} | |
|> Http.send Http.defaultSettings | |
|> Task.map extractBodyText | |
extractBodyText : Http.Response -> Maybe String | |
extractBodyText response = | |
case response.value of | |
Http.Text t -> | |
Just t | |
Http.Blob _ -> | |
Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment