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

Connected

Exercise

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.

Instructions 1/4

undefined XP
  • 1
    • Get a list of all playlists from the playlists API.
  • 2
    • Create a dictionary with Name set to Rock Ballads, then perform a POST request with this dictionary as the data parameter.
  • 3
    • Perform a GET request to get information on the playlist with PlaylistId 2.
  • 4
    • Send a DELETE request to the URL for the playlist with PlaylistId 2 and get the list of existing playlists to confirm removal.