data-platform/app.py

29 lines
705 B
Python
Raw Normal View History

2024-01-09 21:11:45 +08:00
# backend/app.py
from flask import Flask, request, jsonify
from flask_cors import *
app = Flask(__name__)
CORS(app, supports_credentials=True)
todos = []
@app.route("/")
def hello():
return "Hello, World!"
@app.route("/todos", methods=["GET"])
def get_todos():
return jsonify(todos)
@app.route("/todos", methods=["POST"])
def add_todo():
todo = request.json
todos.append(todo)
return jsonify(todo), 201
@app.route("/todos/<int:index>", methods=["DELETE"])
def delete_todo(index):
if index < len(todos):
deleted_todo = todos.pop(index)
return jsonify(deleted_todo)
return "", 404
if __name__ == "__main__":
app.run(debug=True)