IniziaInizia gratis

Creating and deleting resources using an API

Now that you have learned how to construct a URL, you can send requests to specific API resources. Let's see what more you can do with HTTP verbs on these resources.

In this exercise, you will use the playlists API available via http://localhost:3000/playlists/. This API offers the following actions:

Verb Path Description
GET playlists get a list of all playlists
GET /playlists/{PlaylistId} get information on a single playlist using it's unique identifier PlaylistId
POST /playlists create a new playlist
DELETE /playlists/{PlaylistId} remove an existing playlist using it's unique identifier PlaylistId

You will start by getting a list of all existing playlists, then you will learn how to create a new playlist and verify it's creation, and last you will learn how to remove an existing playlist.

The requests library is already imported for your convenience.

Questo esercizio fa parte del corso

Introduction to APIs in Python

Visualizza il corso

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Get a list of all playlists from the API
response = requests.____('____')
print(response.text)
Modifica ed esegui il codice