0
0
Flaskframework~20 mins

Why APIs matter in Flask - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
API Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why do APIs help developers?
Which of the following best explains why APIs are important for developers when building web applications?
AAPIs allow different software to communicate and share data easily, speeding up development.
BAPIs automatically fix bugs in your code without any extra work.
CAPIs replace the need for databases in web applications.
DAPIs make your application run faster by using less memory.
Attempts:
2 left
💡 Hint
Think about how different programs or services work together.
component_behavior
intermediate
2: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!'})
A{"message": "Hello, world!"}
BHello, world!
C<html><body>Hello, world!</body></html>
DError: Route not found
Attempts:
2 left
💡 Hint
Look at the return type and what jsonify does.
📝 Syntax
advanced
2: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}
ANo error, runs successfully
BIndentationError: expected an indented block
CNameError: name 'data' is not defined
DTypeError: 'dict' object is not callable
Attempts:
2 left
💡 Hint
Check the indentation of the function body.
state_output
advanced
2: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})
A{"count": 0}
B{"count": 1}
CError: global variable not allowed
D{"count": 2}
Attempts:
2 left
💡 Hint
Think about how the global variable changes with each call.
🔧 Debug
expert
2: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?
AThe server returns 'Submitted!' even with a GET request.
BThe server returns a 404 Not Found error.
CThe server returns a 405 Method Not Allowed error because GET is not allowed.
DThe server crashes with an internal error.
Attempts:
2 left
💡 Hint
Check the allowed HTTP methods for the route.