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.
Bu egzersiz
Introduction to APIs in Python
kursunun bir parçasıdırUygulamalı interaktif egzersiz
Bu örnek kodu tamamlayarak bu egzersizi bitirin.
# Construct the URL string and pass it to the requests.get() function
response = requests.get('http://localhost:____/____/____')
print(response.text)