Skip to content

Instantly share code, notes, and snippets.

@frpaulas
Created November 9, 2015 17:31
Show Gist options
  • Save frpaulas/7365587ee84f837b6d03 to your computer and use it in GitHub Desktop.
Save frpaulas/7365587ee84f837b6d03 to your computer and use it in GitHub Desktop.
module Saints where
import Http
import Html exposing (Html)
import Task exposing (Task, andThen, toResult)
import Json.Decode as Json exposing ((:=))
-- queries postgres for authentication token
-- displays token
-- successful query comes back with 201 status and body {"token": "longSecretToken"}
-- failure comes back with 401 status and body {"message": "Failed authentication."}
main: Signal Html
main =
Signal.map Html.text readme.signal
port fetchToken: Task Http.Error ()
port fetchToken =
Http.post
getToken
"http://localhost:3000/postgrest/tokens"
(Http.string """{"id": "username", "pass":"password"}""")
`andThen` report
type alias Token = { token: String }
getToken: Json.Decoder Token
getToken =
Json.object1 Token ("token" := Json.string)
report: Token -> Task Http.Error ()
report token =
Signal.send readme.address token.token
readme: Signal.Mailbox String
readme =
Signal.mailbox "Blork"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment