30 lines
801 B
Python
30 lines
801 B
Python
from flask import Flask, jsonify
|
|
|
|
compiti = [
|
|
{"id": 1, "descrizione": "Compito matematica"},
|
|
{"id": 2, "descrizione": "Consegna TPSIT progetto API REST"},
|
|
{"id": 3, "descrizione": "Compito di sistemi"},
|
|
{"id": 4, "descrizione": "Compito di italiano"}
|
|
]
|
|
|
|
app = Flask(__name__)
|
|
|
|
@app.route("/", methods=["GET"])
|
|
def home():
|
|
html = "<h1>Home page API REST Compiti</h1><h2>ciao, 3cx merda</h2>"
|
|
html += "<a href=\"/doc.html\">Documentazione</a>"
|
|
return html, 200
|
|
|
|
@app.route("/compiti", methods=["GET"])
|
|
def get_compiti():
|
|
return jsonify(compiti), 200
|
|
|
|
@app.route("/compiti/<int:id>", methods=["GET"])
|
|
def get_compito_by_id(id):
|
|
for ciscomerda in compiti:
|
|
if ciscomerda["id"] == id:
|
|
return jsonify(ciscomerda), 200
|
|
return jsonify([]), 404
|
|
|
|
app.run(debug=True)
|