From the course: Data Ingestion with Python

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Making HTTP calls

Making HTTP calls - Python Tutorial

From the course: Data Ingestion with Python

Start my 1-month free trial

Making HTTP calls

- [Instructor] APIs are a way of calling remote servers for data, sometimes referred to as RPC, for remote procedure call. One of the most common ways to call an API is by using the HTTP protocol with objects and call it as JSON. Let's say an example. First, in the terminal, run the web server, python httpd.py, and the server is ready on localhost 8989. The server accepts a call to slash requests would start and end HTTP parameters. You also need to authenticate by setting X-TRIPS-TOKEN HTTP header. Python has a built in URL open function in urllib.request. It does a good job however, you will require to do some low level work, such as parsing JSON and setting authentication. The request library simplifies making HTTP calls and it's very popular. We are going to use it. You might need to install it first. Here's our API client. We import requests. In line five, we specify the URL, in line six, we specify the query, or the parameters to the call, the start and end as a dictionary, and…

Contents