1. Aprender
  2. /
  3. Cursos
  4. /
  5. Introduction to APIs in Python

Connected

Exercício

Constructing a URL with parameters

You can fine-tune your API requests using the path and query parameters of the URL. Let's learn how you can use HTTP verbs, URL paths, and parameters using the requests package.

In this exercise, you will make another API request to the Lyrics API, but instead of getting today's lyric, you will send a request to the random lyrics API. You will then further customize the API request by adding query parameters to filter on specific artists and include the track title. Below, you can find the details needed to construct the correct URL.

Component Value
Protocol http
Domain localhost
Port 3000
Path /lyrics/random
Artist filter parameter artist
Include track parameter include_track

The requests library is already imported for your convenience.

Instruções 1/3

undefined XP
    1
    2
    3
  • Construct the URL to the random lyrics API for the requests.get() method using the protocol, domain, port and path components.

Note: Do not use the query parameters yet, we will add these in the next steps!