Complete the code to create a basic Flask API endpoint that returns a greeting message.
from flask import Flask app = Flask(__name__) @app.route('/hello') def hello(): return [1]
The function must return a string as the response. Using quotes around the string is required.
Complete the code to import the Flask class correctly.
[1] Flask
app = Flask(__name__)To use Flask, you import the Flask class from the flask module using 'from flask import Flask'.
Fix the error in the route decorator to correctly define the API endpoint.
@app.route([1]) def greet(): return "Hi there!"
The route path must be a string with quotes, starting with a slash.
Fill both blanks to create a JSON response from the API using Flask's jsonify.
from flask import Flask, [1] app = Flask(__name__) @app.route('/data') def data(): return [2]({'message': 'Hello, JSON!'})
Flask's jsonify function is imported and used to return JSON responses easily.
Fill all three blanks to create a Flask API that accepts a POST request and returns the posted JSON data.
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/postdata', methods=[[1]]) def post_data(): data = request.[2] return jsonify([3])
The route must allow POST method, access JSON data from request.json, and return it with jsonify.