O'Reilly logo

Elixir Cookbook by Paulo A Pereira

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

Pattern matching an HTTPoison response

HTTPoison is an HTTP client for Elixir. We have already used it in the Managing dependencies recipe of Chapter 1, Command Line.

In this recipe, we will create a simple application that will take a URL and fetch the corresponding page, returning either the body or the headers of that request.

Getting ready

We will be using the get_pages application. You will find it in the source code of this book. The steps are as follows:

  1. Enter the application directory:
    > cd get_pages
    
  2. Fetch the dependencies and compile them:
    > mix deps.get && mix deps.compile
    
  3. Start the application:
    > iex –S mix
    

How to do it…

To get an HTTP response and perform pattern matching on it, we will follow these steps:

  1. Issue a request to fetch the

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