A REST API is a way for IoT devices to communicate over the internet using simple web requests like GET and POST. It lets devices send and receive data easily.
Click to reveal answer
beginner
Which HTTP method is commonly used to retrieve data from an IoT device's REST API?
The GET method is used to ask the device for data, like sensor readings, without changing anything on the device.
Click to reveal answer
beginner
Why is JSON often used in REST APIs for IoT devices?
JSON is a simple text format that is easy for both humans and machines to read and write. It helps devices share data clearly and quickly.
Click to reveal answer
intermediate
How does a Raspberry Pi act as a REST API server for an IoT device?
The Raspberry Pi runs a small program that listens for web requests. When it gets a request, it sends back data or performs actions, like turning on a light.
Click to reveal answer
intermediate
What is the role of endpoints in a REST API for IoT devices?
Endpoints are specific web addresses on the device where you can send requests to get data or control the device. Each endpoint does a different job.
Click to reveal answer
Which HTTP method would you use to update the settings of an IoT device via REST API?
AGET
BPUT
CDELETE
DPOST
✗ Incorrect
PUT is used to update or replace data on the device, such as changing settings.
What data format is most commonly used to send data in REST APIs for IoT devices?
AYAML
BXML
CCSV
DJSON
✗ Incorrect
JSON is lightweight and easy to use, making it the most popular format for REST APIs.
In a REST API, what is an endpoint?
AA web address to access specific data or functions
BA type of sensor
CA programming language
DA hardware component
✗ Incorrect
Endpoints are URLs where you send requests to interact with the device.
Which device can be used to host a REST API server for an IoT project?
APrinter
BSmartphone only
CRaspberry Pi
DMonitor
✗ Incorrect
Raspberry Pi is a small computer that can run a REST API server for IoT devices.
What does the GET method do in a REST API?
ARetrieves data
BUpdates data
CDeletes data
DCreates new data
✗ Incorrect
GET requests ask the server to send back data without changing anything.
Explain how a Raspberry Pi can be set up to provide a REST API for an IoT device.
Think about how the Pi acts like a small website that devices can talk to.
You got /4 concepts.
Describe the role of HTTP methods in controlling an IoT device through a REST API.
Consider how you tell the device what to do using web requests.
You got /4 concepts.
Practice
(1/5)
1. What is the main purpose of a REST API on a Raspberry Pi IoT device?
easy
A. To connect the Raspberry Pi to a monitor
B. To allow remote communication and control over the network
C. To store large amounts of data locally
D. To increase the Raspberry Pi's processing speed
Solution
Step 1: Understand REST API role
A REST API enables devices to communicate over a network using standard web protocols.
Step 2: Identify IoT device needs
IoT devices use REST APIs to send sensor data or receive commands remotely.
Final Answer:
To allow remote communication and control over the network -> Option B
Quick Check:
REST API = Remote communication [OK]
Hint: REST APIs enable network communication for IoT devices [OK]
Common Mistakes:
Confusing REST API with hardware speed
Thinking REST API stores data locally
Assuming REST API connects to display devices
2. Which Python library is commonly used on Raspberry Pi to create a REST API for IoT devices?
easy
A. Flask
B. NumPy
C. Pandas
D. Matplotlib
Solution
Step 1: Identify common Python libraries
NumPy, Pandas, and Matplotlib are for data processing and visualization, not REST APIs.
Step 2: Recognize Flask's role
Flask is a lightweight web framework used to build REST APIs easily on Raspberry Pi.
Final Answer:
Flask -> Option A
Quick Check:
Flask = REST API framework [OK]
Hint: Flask is the go-to Python web framework for REST APIs [OK]
Common Mistakes:
Choosing data libraries instead of web frameworks
Confusing Flask with data analysis tools
Assuming Matplotlib creates APIs
3. What will be the output of this Flask route code on a Raspberry Pi?
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/sensor')
def sensor():
data = {'temperature': 22, 'humidity': 60}
return jsonify(data)
# Assume app is running and /sensor is requested
medium
A. {"temperature": 22, "humidity": 60}
B. temperature=22, humidity=60
C. temperature: 22, humidity: 60
D. Error: jsonify not defined
Solution
Step 1: Understand jsonify function
jsonify converts Python dict to JSON string with correct headers for API response.
Step 2: Analyze route output
The route returns JSON with keys 'temperature' and 'humidity' and their values.
Final Answer:
{"temperature": 22, "humidity": 60} -> Option A
Quick Check:
jsonify(dict) = JSON string [OK]
Hint: jsonify returns JSON string from dict in Flask [OK]
Common Mistakes:
Expecting plain text instead of JSON
Confusing jsonify with HTML output
Missing import of jsonify causing errors
4. Identify the error in this Flask route code for Raspberry Pi IoT device:
from flask import Flask
app = Flask(__name__)
@app.route('/led/on')
def led_on():
GPIO.output(17, True)
return 'LED is ON'
medium
A. Return statement must be JSON, not string
B. Route decorator syntax is incorrect
C. Missing import and setup for GPIO module
D. Flask app is not created properly
Solution
Step 1: Check GPIO usage
GPIO module must be imported and configured before use to control pins.
Step 2: Verify code completeness
Code lacks 'import RPi.GPIO as GPIO' and GPIO setup like GPIO.setmode() and GPIO.setup().
Final Answer:
Missing import and setup for GPIO module -> Option C
Quick Check:
GPIO needs import and setup before use [OK]
Hint: Always import and setup GPIO before controlling pins [OK]
Common Mistakes:
Assuming Flask route syntax is wrong
Thinking return must be JSON always
Ignoring GPIO initialization steps
5. You want to create a REST API on Raspberry Pi that returns sensor data only if temperature is above 25°C. Which code snippet correctly implements this logic using Flask?
hard
A. from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/sensor')
def sensor():
temp = 30
if temp >= 25:
return {'temperature': temp}
else:
return {'message': 'Temperature too low'}
B. from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/sensor')
def sensor():
temp = 20
if temp < 25:
return jsonify({'temperature': temp})
else:
return jsonify({'message': 'Temperature too low'})
C. from flask import Flask
app = Flask(__name__)
@app.route('/sensor')
def sensor():
temp = 30
if temp > 25:
return {'temperature': temp}
else:
return {'message': 'Temperature too low'}
D. from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/sensor')
def sensor():
temp = 30
if temp > 25:
return jsonify({'temperature': temp})
else:
return jsonify({'message': 'Temperature too low'})
Solution
Step 1: Check temperature condition logic
We want to return data only if temperature is above 25, so 'temp > 25' is correct.
Step 2: Verify response format
Flask needs jsonify to return proper JSON response with correct headers.
Final Answer:
Code with temp=30, condition temp > 25, and jsonify responses -> Option D
Quick Check:
Use temp > 25 and jsonify for JSON response [OK]
Hint: Use if temp > 25 and jsonify() to return JSON [OK]
Common Mistakes:
Using wrong temperature comparison operator
Returning dict without jsonify causing errors
Setting temperature below threshold incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.