APIs With Python

This quiz checks what you know about working with APIs in Python. APIs let your code talk to other services like getting data from websites or sending info to apps making your programs more powerful and connected!

Last Updated :
Discuss
Comments

Question 1

What does the requests.get() function do in Python?

  • Updates data on the server

  • Retrieves data from a URL

  • Deletes data on the server

  • Uploads files

Question 2

What will this code return if the request is successful?

Python
import requests
response = requests.get("https://api.github.com")
print(response.status_code)


  • 404

  • 500

  • 200

  • None

Question 3

Which of these methods is used to send data to a server in a request body?

  • GET

  • POST

  • DELETE

  • HEAD

Question 4

What does the response.json() method return in Python’s requests module?

  • The raw string of the response

  • A dictionary from the JSON response

  • An XML document

  • List of headers

Question 5

What will happen if you access a URL with an invalid SSL certificate using requests without disabling verification?

  • It returns status code 200

  • It raises an SSLError

  • It auto-validates the SSL

  • It retries the request

Question 6

How can you disable SSL verification in Python requests?

  • verify=False in get() method

  • Remove headers

  • Use http instead of https

  • Use json=False

Question 7

Which requests method can be used to modify part of a resource on a server?

  • PATCH

  • PUT

  • DELETE

  • GET

Question 8

What is the purpose of a Session object in the requests module?

  • To upload files

  • To manage browser sessions

  • To persist cookies and connection pooling

  • To track request history

Question 9

In the following code, what does params do?

Python
params = {
    "country": "us",
    "apiKey": API_KEY,
}
response = requests.get(url, params=params)


  • It adds authentication headers

  • It sets up a timeout

  • It adds query parameters to the URL

  • It disables SSL

Question 10

What does this line do in a Python script using the NewsAPI?

Python
articles = response.json().get('articles', [])


  • Loads XML content

  • Returns all articles in JSON data

  • Returns first image only

  • Returns 404 if articles not found

There are 12 questions to complete.

Take a part in the ongoing discussion