0
0
Rest APIprogramming~15 mins

Example requests and responses in Rest API - Mini Project: Build & Apply

Choose your learning style9 modes available
Example requests and responses
📖 Scenario: You are learning how to work with REST APIs by creating example requests and responses in Python.
🎯 Goal: Build a simple Python script that shows an example GET request and its expected JSON response.
📋 What You'll Learn
Create a dictionary representing the JSON response from an API
Create a string variable representing the example GET request URL
Print the example request and the JSON response
💡 Why This Matters
🌍 Real World
Developers often write example requests and responses to document APIs or test them.
💼 Career
Understanding how to format and display API requests and responses is important for backend and frontend developers.
Progress0 / 4 steps
1
Create example JSON response data
Create a dictionary called response_data with these exact entries: 'userId': 1, 'id': 101, 'title': 'Learn REST APIs', 'completed': false
Rest API
Need a hint?

Use curly braces {} to create a dictionary with the exact keys and values.

2
Create example GET request URL
Create a string variable called example_request and set it to the exact value 'GET /todos/101 HTTP/1.1'
Rest API
Need a hint?

Use quotes to create a string exactly as shown.

3
Prepare output strings
Create a string variable called response_json that converts response_data to a JSON string using import json and json.dumps()
Rest API
Need a hint?

Use import json at the top and then json.dumps() to convert the dictionary.

4
Print example request and response
Print the example_request string and then print the response_json string on separate lines
Rest API
Need a hint?

Use two print statements, one for the request and one for the JSON response.