Skip to content

Python Request Guide

Introduction

This guide will demonstrate how to make a request to an API endpoint using Python. We’ll use the Movies endpoint from DummyAPI as an example. For more details, refer to the Movies Endpoint Documentation.

Step 1: Set Up Your Environment

  • Local Environment: Ensure you have Python installed. Create a new Python file, e.g., request_movies.py.
  • Online IDE: Use platforms like Repl.it or PythonAnywhere.

Step 2: Install Requests Library

If you haven’t already, install the requests library:

Terminal window
pip install requests

Step 3: Write the Request

In your Python file or online editor, write the following request:

import requests
response = requests.get('https://dummyapi.online/api/movies')
if response.status_code == 200:
print(response.json())
else:
print(f"Error: {response.status_code}")

This script sends a GET request to the DummyAPI Movies endpoint and prints the response.

Step 4: Run Your Code

  • Local Environment: Run your file in your terminal: python request_movies.py.
  • Online IDE: Execute the code directly in the platform.

Step 5: View the Results

Check the output of your environment. You should see the JSON response from the API, listing movies.

Output
[
{
id: 1,
movie: 'The Shawshank Redemption',
rating: 9.2,
image: 'images/shawshank.jpg',
imdb_url: 'https://www.imdb.com/title/tt0111161/'
},
{
id: 2,
movie: 'The Godfather',
rating: 9.2,
image: 'images/godfather.jpg',
imdb_url: 'https://www.imdb.com/title/tt0068646/'
},
...
]

Conclusion

You’ve successfully made an API request to the DummyAPI Movies endpoint using Python. Explore DummyAPI for other endpoints and data you can work with.