Make a Request

Making a request with Requests is very simple.

Begin by importing the Requests module:

  1. >>> import requests

Now, let’s try to get a webpage. For this example, let’s get GitHub’s public timeline

  1. >>> r = requests.get('https://api.github.com/events')

Now, we have a Response object called r. We can get all the information we need from this object.

Requests’ simple API means that all forms of HTTP request are as obvious. For example, this is how you make an HTTP POST request:

  1. >>> r = requests.post('http://httpbin.org/post', data = {'key':'value'})

Nice, right? What about the other HTTP request types: PUT, DELETE, HEAD and OPTIONS? These are all just as simple:

  1. >>> r = requests.put('http://httpbin.org/put', data = {'key':'value'})
  2. >>> r = requests.delete('http://httpbin.org/delete')
  3. >>> r = requests.head('http://httpbin.org/get')
  4. >>> r = requests.options('http://httpbin.org/get')

That’s all well and good, but it’s also only the start of what Requests can do.