Fetch from HTTP APIs

In this section, you will use the Http module to fetch an initial photo from an API endpoint. You will see how Elm treats HTTP requests differently from most JavaScript applications and learn why that’s important. You will learn how to use commands to issue HTTP requests and how to represent missing information with another special type called Maybe. You will also discover how to use pattern matching on the Result type to extract a successful value or an error for error handling.

Create a Command

The Http module does not ship with Elm’s core library, thus the first order of business is to install it. Inside your picshare directory, run this command and accept the prompt:

 elm install elm/http

Next, import the Http module ...

Get Programming Elm now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.