1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to APIs in Python

Connected

Exercise

Using request and response headers

Headers contain additional information about your API calls, including the desired or used response format. Using accept and content-type headers, client and server can negotiate what response format to use.

In this exercise, you'll use headers to inspect response formats after making a request and make a new request specifying the desired format via the accept header.

The requests package has been imported for your convenience.

Instructions 1/3

undefined XP
  • 1

    Find out the content-type of the response by printing out the response content-type header.

  • 2

    Find out what content-types the server can respond with by printing out the response accept header.

  • 3

    Add an accept header to the request so the server returns JSON formatted data, then print the response text attribute.