Recall & Review
beginner
What is a Flask route?
A Flask route is a URL pattern that tells Flask which function to run when a user visits that URL. It connects web addresses to Python functions.
Click to reveal answer
beginner
How do you define a route in Flask to respond to a GET request?
Use the @app.route decorator with the URL path and set methods=['GET']. For example:<br>
@app.route('/api/data', methods=['GET'])Click to reveal answer
beginner
What does the function decorated by a Flask route return?
It returns the response sent to the client. This can be a string, JSON data, or an HTML page.
Click to reveal answer
intermediate
How do you return JSON data from a Flask route?
Use Flask's jsonify function to convert Python data to JSON and send it as a response.<br>Example:<br>
return jsonify({'key': 'value'})Click to reveal answer
intermediate
Why is it important to specify HTTP methods in Flask routes?
Specifying methods like GET or POST tells Flask which types of requests the route can handle. This helps organize API behavior and improves security.
Click to reveal answer
Which decorator is used to create a route in Flask?
✗ Incorrect
The @app.route decorator defines a URL route in Flask.
How do you specify that a Flask route should only accept POST requests?
✗ Incorrect
You specify allowed HTTP methods using methods=['POST'] in the route decorator.
What does the Flask function jsonify do?
✗ Incorrect
jsonify converts Python dictionaries or lists into JSON format for API responses.
If you want a route to respond to both GET and POST requests, how do you specify it?
✗ Incorrect
You list allowed methods as a list: methods=['GET', 'POST'].
What will happen if you visit a Flask route URL that only accepts POST but you send a GET request?
✗ Incorrect
Flask returns a 405 error when the HTTP method is not allowed for the route.
Explain how to create a simple Flask API endpoint that returns JSON data when accessed via a GET request.
Think about how you connect a URL to a function and send back JSON.
You got /3 concepts.
Describe why specifying HTTP methods in Flask routes is important for API design.
Consider what happens if you don't limit request types.
You got /4 concepts.