make HTTP requests

This commit is contained in:
Cadey Ratio 2020-11-15 16:08:41 -05:00
parent 863aec0e5b
commit c85bb78f6c
2 changed files with 41 additions and 13 deletions

View File

@ -7,7 +7,6 @@
<link rel="icon" type="image/png" href="/static/favicon.png"/> <link rel="icon" type="image/png" href="/static/favicon.png"/>
<link rel="icon" href="/static/favicon.ico" type="image/x-icon"/> <link rel="icon" href="/static/favicon.ico" type="image/x-icon"/>
<link rel="manifest" href="/static/manifest.json" /> <link rel="manifest" href="/static/manifest.json" />
<div id="root"></div>
</head> </head>
<body id="top"> <body id="top">
<main> <main>
@ -18,6 +17,7 @@
node: document.getElementById("app") node: document.getElementById("app")
}); });
</script> </script>
<script src="/static/install-sw.js"></script>
</main> </main>
</body> </body>
</html> </html>

View File

@ -1,32 +1,60 @@
module Main exposing (..) module Main exposing (..)
import Browser import Browser
import Html exposing (Html, div, h1, img, text) import Html exposing (Html, div, h1, img, p, pre, text)
import Html.Attributes exposing (src) import Html.Attributes exposing (src)
import Http
import Mi
type alias Model = type Model
{} = Failure String
| Loading
| Success String
init : ( Model, Cmd Msg ) init : () -> ( Model, Cmd Msg )
init = init _ =
( {}, Cmd.none ) ( Loading
, Http.get
{ url = "/.within/botinfo"
, expect = Http.expectString GotText
}
)
type Msg type Msg
= NoOp = GotText (Result Http.Error String)
update : Msg -> Model -> ( Model, Cmd Msg ) update : Msg -> Model -> ( Model, Cmd Msg )
update msg model = update msg model =
( model, Cmd.none ) case msg of
GotText result ->
case result of
Ok fullText ->
( Success fullText, Cmd.none )
Err why ->
( Failure (Mi.errorToString why), Cmd.none )
view : Model -> Html Msg view : Model -> Html Msg
view model = view model =
case model of
Failure why ->
div [] div []
[ h1 [] [ text "Your Elm App is working!" ] [ h1 [] [ text "Error" ]
, p [] [ text why ]
]
Loading ->
div [] [ h1 [] [ text "Loading" ] ]
Success msg ->
div []
[ h1 [] [ text "Mi" ]
, pre [] [ text msg ]
] ]
@ -34,7 +62,7 @@ main : Program () Model Msg
main = main =
Browser.element Browser.element
{ view = view { view = view
, init = \_ -> init , init = init
, update = update , update = update
, subscriptions = always Sub.none , subscriptions = always Sub.none
} }