Lesson 39. Making HTTP requests in Haskell

 

After reading lesson 39, you’ll be able to

  • Fetch web pages by using Haskell
  • Generate more complex requests by setting headers and using HTTPS
  • Understand how to approach learning new Haskell types and libraries

In this lesson, you’ll learn how to make an HTTP request in Haskell and save the results to a file. The data you’ll fetch is from the National Oceanic and Atmospheric Administration (NOAA) Climate Data API. This API requires you to send a custom HTTP request that uses SSL and has a custom header for authentication. You’ll use the Network.HTTP.Simple library, which will allow you to make simple requests as well as create custom HTTP requests. You’ll start by learning how to use Network.HTTP.Simple to fetch a web page from a URL. Then you’ll create a specific request for the NOAA API. In the end, you’ll have fetched JSON data from this API to be used in the next lesson.

Consider this

How would you go about writing a Haskell program that when ran would fetch the homepage of reddit.com and write it to a local .html file?

39.1. Getting your project set up

39.2. Using the HTTP.Simple module

39.3. Making an HTTP request

39.4. Putting it all together

Summary