0
0
Rest APIprogramming~10 mins

Interactive API explorers in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to open the API explorer URL in a browser.

Rest API
import webbrowser

webbrowser.[1]('https://api.example.com/explorer')
Drag options to blanks, or click blank then click option'
Aclose
Bwrite
Cread
Dopen
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'close' instead of 'open' will not open the browser.
2fill in blank
medium

Complete the code to send a GET request to the API explorer endpoint.

Rest API
import requests

response = requests.[1]('https://api.example.com/explorer')
print(response.status_code)
Drag options to blanks, or click blank then click option'
Apost
Bget
Cdelete
Dput
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' sends data instead of retrieving it.
3fill in blank
hard

Fix the error in the code to parse JSON response from the API explorer.

Rest API
import requests

response = requests.get('https://api.example.com/explorer')
data = response.[1]()
print(data)
Drag options to blanks, or click blank then click option'
Ajson
Btext
Ccontent
Dhtml
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text' returns raw string, not parsed JSON.
4fill in blank
hard

Fill both blanks to create a function that fetches and returns JSON data from the API explorer.

Rest API
import requests

def fetch_data(url):
    response = requests.[1](url)
    return response.[2]()
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cjson
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'post' instead of 'get' will send data, not retrieve.
5fill in blank
hard

Fill all three blanks to build a function that sends a POST request with JSON data to the API explorer and returns the JSON response.

Rest API
import requests

def post_data(url, payload):
    response = requests.[1](url, json=[2])
    return response.[3]()
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cjson
Dpayload
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'post' will not send data.