MulaiMulai sekarang secara 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.

Latihan ini adalah bagian dari kursus

Introduction to APIs in Python

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# Get a list of all playlists from the API
response = requests.____('____')
print(response.text)
Edit dan Jalankan Kode