0
0
Flaskframework~10 mins

JSON request parsing in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Flask module correctly.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Ajsonify
Brender_template
Crequest
DFlask
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'request' instead of 'Flask'
Using 'jsonify' here instead of 'Flask'
2fill in blank
medium

Complete the code to access JSON data from a POST request.

Flask
data = [1].get_json()
Drag options to blanks, or click blank then click option'
Arequest
Bjson
CFlask
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'json.get_json()' which is incorrect
Trying to call get_json() on 'app' or 'Flask'
3fill in blank
hard

Fix the error in the route decorator to accept POST requests.

Flask
@app.route('/submit', methods=[[1]])
Drag options to blanks, or click blank then click option'
A'POST'
B'PUT'
C'DELETE'
D'GET'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'GET' which is default but does not accept JSON body
Using 'PUT' or 'DELETE' which are different HTTP methods
4fill in blank
hard

Fill both blanks to return a JSON response with a message and status code 200.

Flask
return [1]({'message': 'Success'}), [2]
Drag options to blanks, or click blank then click option'
Ajsonify
B201
C200
Dmake_response
Attempts:
3 left
💡 Hint
Common Mistakes
Returning a plain dict without jsonify
Using status code 201 which means created
5fill in blank
hard

Fill all three blanks to parse JSON, extract 'name', and return a greeting message.

Flask
data = [1].get_json()
name = data.get([2], 'Guest')
return [3]({'greeting': f'Hello, {name}!'})
Drag options to blanks, or click blank then click option'
Arequest
B'name'
Cjsonify
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'app' instead of 'request'
Not using jsonify to return JSON response