Bird
Raised Fist0
Rest APIprogramming~20 mins

Why REST APIs exist - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
REST API Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Purpose of REST APIs
Why do REST APIs exist in software development?
ATo store large amounts of data locally on a user's device
BTo compile source code into machine code
CTo create graphical user interfaces for desktop applications
DTo allow different software systems to communicate over the internet using a standard set of rules
Attempts:
2 left
💡 Hint
Think about how apps and websites talk to each other over the internet.
❓ Predict Output
intermediate
2:00remaining
Output of a REST API call simulation
What is the output of this simulated REST API call in Python?
Rest API
def get_user():
    return {'id': 1, 'name': 'Alice'}

response = get_user()
print(response['name'])
AAlice
B1
C{'id': 1, 'name': 'Alice'}
DKeyError
Attempts:
2 left
💡 Hint
Look at what key is accessed in the dictionary.
🔧 Debug
advanced
2:00remaining
Identify the error in REST API response handling
What error will this code produce when handling a REST API response?
Rest API
response = {'status': 404, 'message': 'Not Found'}
print(response['data'])
AValueError
BTypeError
CKeyError
DNo error, prints None
Attempts:
2 left
💡 Hint
Check if the key 'data' exists in the dictionary.
📝 Syntax
advanced
2:00remaining
Syntax error in REST API request code
Which option contains a syntax error in this Python REST API request snippet?
Rest API
import requests
response = requests.get('https://api.example.com/data')
print(response.json())
A
import requests
response = requests.get('https://api.example.com/data')
print(response.json())
B
import requests
response = requests.get('https://api.example.com/data'
print(response.json())
C
import requests
response = requests.get('https://api.example.com/data')
print(response.json)
D
))(nosj.esnopser(tnirp
)'atad/moc.elpmaxe.ipa//:sptth'(teg.stseuqer = esnopser
stseuqer tropmi
Attempts:
2 left
💡 Hint
Look for missing or extra parentheses.
🚀 Application
expert
2:00remaining
Number of items in REST API JSON response
Given this JSON response from a REST API, how many user objects does it contain?
Rest API
response = {
  "users": [
    {"id": 1, "name": "Alice"},
    {"id": 2, "name": "Bob"},
    {"id": 3, "name": "Charlie"}
  ]
}

count = len(response['users'])
print(count)
A3
B1
C2
D0
Attempts:
2 left
💡 Hint
Count the number of dictionaries inside the 'users' list.

Practice

(1/5)
1. Why do REST APIs exist in software development?
easy
A. To allow different programs to communicate over the internet using simple rules
B. To create complex user interfaces for websites
C. To store data only on local machines
D. To replace all programming languages with one standard

Solution

  1. Step 1: Understand the purpose of REST APIs

    REST APIs are designed to let different software programs talk to each other over the internet easily.
  2. Step 2: Compare options with this purpose

    Only To allow different programs to communicate over the internet using simple rules correctly describes this purpose. Options A, B, and C do not relate to REST APIs' main goal.
  3. Final Answer:

    To allow different programs to communicate over the internet using simple rules -> Option A
  4. Quick Check:

    REST APIs exist for communication = D [OK]
Hint: REST APIs help programs talk over the internet simply [OK]
Common Mistakes:
  • Thinking REST APIs create user interfaces
  • Believing REST APIs store data locally only
  • Assuming REST APIs replace programming languages
2. Which HTTP method is commonly used in REST APIs to retrieve data from a server?
easy
A. GET
B. POST
C. DELETE
D. PUT

Solution

  1. Step 1: Recall HTTP methods in REST APIs

    GET is the method used to request and retrieve data from a server.
  2. Step 2: Match the method to the action

    POST sends data, DELETE removes data, PUT updates data. Only GET retrieves data.
  3. Final Answer:

    GET -> Option A
  4. Quick Check:

    Retrieve data = GET [OK]
Hint: GET means get data from server in REST APIs [OK]
Common Mistakes:
  • Confusing POST with GET for data retrieval
  • Using DELETE or PUT to get data
  • Not knowing HTTP method purposes
3. What will be the output of this REST API call?
GET /users/123

Assuming user 123 exists and the API returns JSON data.
medium
A. 500 Internal Server Error
B. {"id":123,"name":"Alice"}
C. 404 Not Found
D. {"error":"User not found"}

Solution

  1. Step 1: Understand the GET request to /users/123

    This request asks the server for data about user with ID 123.
  2. Step 2: Check the condition given

    The user 123 exists, so the server returns the user's data in JSON format.
  3. Final Answer:

    {"id":123,"name":"Alice"} -> Option B
  4. Quick Check:

    Existing user GET returns data = C [OK]
Hint: GET existing user returns JSON data, not error [OK]
Common Mistakes:
  • Choosing error responses when user exists
  • Confusing 404 with successful data return
  • Not recognizing JSON format
4. Identify the error in this REST API usage:
POST /users/123

What is wrong if the goal is to update user 123's data?
medium
A. The URL should not include the user ID
B. GET method should be used to update data
C. POST is used instead of PUT for updating existing data
D. DELETE method is required to update data

Solution

  1. Step 1: Understand HTTP methods for REST APIs

    POST is usually for creating new data, PUT is for updating existing data.
  2. Step 2: Match method to action

    Since the goal is to update user 123, PUT should be used instead of POST.
  3. Final Answer:

    POST is used instead of PUT for updating existing data -> Option C
  4. Quick Check:

    Update needs PUT, not POST = B [OK]
Hint: Use PUT to update existing data, not POST [OK]
Common Mistakes:
  • Using POST to update instead of PUT
  • Thinking GET updates data
  • Believing DELETE updates data
5. You want to design a REST API that allows clients to list all products and add new products. Which HTTP methods and URLs should you use?
hard
A. DELETE /products to list, PUT /products to add new
B. POST /products to list, GET /products to add new
C. PUT /products to list, DELETE /products to add new
D. GET /products to list, POST /products to add new

Solution

  1. Step 1: Identify methods for listing and adding

    GET is used to retrieve or list data, POST is used to create or add new data.
  2. Step 2: Match methods with URLs

    Both actions use the /products URL; GET lists products, POST adds new products.
  3. Final Answer:

    GET /products to list, POST /products to add new -> Option D
  4. Quick Check:

    List = GET, Add = POST = A [OK]
Hint: GET lists, POST adds new resources in REST APIs [OK]
Common Mistakes:
  • Swapping GET and POST roles
  • Using DELETE or PUT incorrectly
  • Confusing URLs for different actions
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard