Last active
November 7, 2016 22:28
-
-
Save focusaurus/64973ffb374ea4942f3ce82e685fe728 to your computer and use it in GitHub Desktop.
How to handle Http POST
This file contains hidden or 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
module SignIn exposing (..) | |
import Html exposing (..) | |
import Html.App | |
import Http | |
import Json.Decode | |
import Task | |
type alias Model = | |
{ signInMessage : String | |
} | |
model : Model | |
model = | |
{ signInMessage = "Request not sent" | |
} | |
type Message | |
= SignInStart | |
| SignInSucceed String | |
| SignInFail Http.Error | |
view : Model -> Html Message | |
view model = | |
label [] [ text model.signInMessage ] | |
update : Message -> Model -> ( Model, Cmd Message ) | |
update message model = | |
case message of | |
SignInStart -> | |
( { model | signInMessage = "Signing in..." }, Cmd.none ) | |
SignInSucceed _ -> | |
( { model | signInMessage = "Sign in succeeded" }, Cmd.none ) | |
SignInFail error -> | |
( { model | signInMessage = "Sign in failed" ++ toString error }, Cmd.none ) | |
init = | |
( model, Task.perform SignInFail SignInSucceed (Http.post Json.Decode.succeed "sign-in" (Http.string """{"email":"[email protected]","password":"bar"}""")) ) | |
main : Program Never | |
main = | |
Html.App.program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = (\model -> Sub.none) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiler error message is: