Posts

Showing posts from December, 2018

Python: Consuming HTTP APIs

Hyper Text Transfer Protocol (HTTP) based APIs are ubiquious in the Internet these days. Whether they are in the form of Simple Object Access Protocol (SOAP), Representational State Transfer (REST) or simple GET/POST requests, HTTP based API's are the de-facto standard for consuming services over the web. In this article, we take a look how to consume these HTTP API's from Python. There are three main modules that can be used to make HTTP API calls in Python, urllib , httplib and requests . Under the hood, requests uses urllib which in turn uses some functionality of httplib . Hence requests provides the most abstraction and ease of use among the three and we will be using that in this article. The following code shows how to make simple GET and POST requests using the requests module. The GET will download the main page of the site https://cbelwal.blogspot.com which the POST will make a POST call and will get the 405 error. Note that we are accessing the URL over SSL an