In this chapter, we learned how to fetch data from a server by sending an HTTP GET
request. The Http.get
function offers a simple syntax for specifying the url and format of the data.
We handed off the command returned by Http.get
to the Elm runtime. We then used the decoders from Json.Decode
module to translate JSON values to Elm data structures. Along the way, we learned how to fire commands when an app is being initialized.
Finally, we used a third-party package called krisajenkins/remotedata
to improve our UI by properly handling all four states an HTTP request can be in at any given time. Those four states are: NotAsked
, Loading
, Success
, and Failure
.
In the next chapter, we’ll learn how to use the POST
, PATCH
, and DELETE
HTTP requests to create, update, and delete a resource respectively.