Challenge - 5 Problems
API Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate2:00remaining
Why do APIs help developers?
Which of the following best explains why APIs are important for developers when building web applications?
Attempts:
2 left
💡 Hint
Think about how different programs or services work together.
✗ Incorrect
APIs act like bridges that let different software talk to each other, making it easier and faster to build features without starting from scratch.
❓ component_behavior
intermediate2:00remaining
What does this Flask API endpoint return?
Given this Flask code, what will the API return when accessed at '/hello'?
Flask
from flask import Flask, jsonify app = Flask(__name__) @app.route('/hello') def hello(): return jsonify({'message': 'Hello, world!'})
Attempts:
2 left
💡 Hint
Look at the return type and what jsonify does.
✗ Incorrect
The jsonify function converts the dictionary into a JSON response, so the API returns a JSON string with the message.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this Flask route
What error will this Flask code produce?
Flask
from flask import Flask app = Flask(__name__) @app.route('/data') def data(): return {'data': 123}
Attempts:
2 left
💡 Hint
Check the indentation of the function body.
✗ Incorrect
The return statement is not indented inside the function, causing an IndentationError.
❓ state_output
advanced2:00remaining
What is the output of this Flask API with state?
Consider this Flask app code. What will the API return after two calls to '/count'?
Flask
from flask import Flask, jsonify app = Flask(__name__) count = 0 @app.route('/count') def count_route(): global count count += 1 return jsonify({'count': count})
Attempts:
2 left
💡 Hint
Think about how the global variable changes with each call.
✗ Incorrect
Each call increases the count by 1. After two calls, count is 2, so the API returns {'count': 2}.
🔧 Debug
expert2:00remaining
Why does this Flask API return a 405 Method Not Allowed error?
This Flask route is defined as:
@app.route('/submit', methods=['POST'])
def submit():
return 'Submitted!'
What happens if you try to access '/submit' with a browser GET request?
Attempts:
2 left
💡 Hint
Check the allowed HTTP methods for the route.
✗ Incorrect
The route only accepts POST requests. A GET request is not allowed, so Flask returns a 405 error.