0
0
Raspberry Piprogramming~10 mins

REST API for IoT device in Raspberry Pi - 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 library needed to create a REST API.

Raspberry Pi
from [1] import Flask
Drag options to blanks, or click blank then click option'
Arequests
BFlask
Cflask
Djson
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Flask' instead of 'flask' as the module name.
2fill in blank
medium

Complete the code to create a Flask app instance named 'app'.

Raspberry Pi
app = [1](__name__)
Drag options to blanks, or click blank then click option'
Aflask
BFlask
CApp
Dapplication
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'flask' instead of 'Flask'.
3fill in blank
hard

Fix the error in the route decorator to handle GET requests at '/status'.

Raspberry Pi
@app.route('/status', methods=[[1]])
Drag options to blanks, or click blank then click option'
A'GET'
B'POST'
C'PUT'
D'DELETE'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'POST' or other HTTP methods instead of 'GET'.
4fill in blank
hard

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

Raspberry Pi
return [1]({'status': 'online'}), [2]
Drag options to blanks, or click blank then click option'
Ajsonify
B200
Cjson
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Returning plain dict without jsonify.
Using wrong status code like 404.
5fill in blank
hard

Fill all three blanks to run the Flask app on host '0.0.0.0' and port 5000 with debug mode on.

Raspberry Pi
if __name__ == '__main__':
    app.run(host=[1], port=[2], debug=[3])
Drag options to blanks, or click blank then click option'
A'127.0.0.1'
B5000
CTrue
D'0.0.0.0'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '127.0.0.1' limits access to localhost only.
Setting debug to False disables helpful error messages.