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

View File

@ -1,40 +1,68 @@
module Main exposing (..)
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 Http
import Mi
type alias Model =
{}
type Model
= Failure String
| Loading
| Success String
init : ( Model, Cmd Msg )
init =
( {}, Cmd.none )
init : () -> ( Model, Cmd Msg )
init _ =
( Loading
, Http.get
{ url = "/.within/botinfo"
, expect = Http.expectString GotText
}
)
type Msg
= NoOp
= GotText (Result Http.Error String)
update : Msg -> Model -> ( Model, Cmd Msg )
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 =
div []
[ h1 [] [ text "Your Elm App is working!" ]
]
case model of
Failure why ->
div []
[ h1 [] [ text "Error" ]
, p [] [ text why ]
]
Loading ->
div [] [ h1 [] [ text "Loading" ] ]
Success msg ->
div []
[ h1 [] [ text "Mi" ]
, pre [] [ text msg ]
]
main : Program () Model Msg
main =
Browser.element
{ view = view
, init = \_ -> init
, init = init
, update = update
, subscriptions = always Sub.none
}