In the websites and applications that we'll build using Rails, we want to be able to use information from the outside world to give our website functionality. Whether it's pulling weather information (like we did in our lab) or interfacing with data from Google Maps, we need efficient ways to send and receive information.

API's make it easy for us to do this. As a technical definition, an API is a way for two servers to interact with one another. When building our Weather app, we set up an Weather API client that would send GET requests to a server with parameters including information about the City and receive back the actual Weather.

They range in size and format, from large and complex ones like Google's ecosystem, to simpler ones like our Weather client, to drop dead simple Quote API's.

You start by installing the gem Faraday

At the top of a ruby file in which you'd like to use Faraday, include:

require 'faraday'

With Faraday, we can send requests ( GET,PATCH, PUT, POST, DELETE) to receive, update, or send the information that our application needs. We've already been doing this internally with our labs and projects - now we're simply accessing information hosted elsewhere.

Let's look at how we can call a get request using Faraday. We'll be using a Quote API for now.

GET

response = Faraday.get '<https://favqs.com/api/qotd>'

After doing this, response will be equal the following:

<Faraday::Response:0x00005577a1fc56e8>

This is because our Faraday response object from the API call will be divided into a few things, the most significant being our status and body. If we look at response.status, (if successful), it'll be equal to

200