Use Req to Make Requests
Req is quite simple to use for a majority of cases. For example, you would call Req.get!("https://www.google.com") to fetch the Google home page. For more advanced use cases, Req can be customized to include custom headers, authentication, or anything that you need.
For our app, we’ll take advantage of Req.new/1 to create an HTTP client that can be used against our API. Once we have that, we’ll create a context module to use the API in our application. Let’s dive in!
Implement API-Client Module
Create a file at lib/phone_app/twilio/api.ex and type the following code:
1: | defmodule PhoneApp.Twilio.Api do |
- | defp twilio_config do |
- | Application.fetch_env!(:phone_app, :twilio ... |
Get From Ruby to Elixir now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.