O'Reilly logo

Programming Elm by Jeremy Fairbank

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required