from flask import Flask, jsonify, request
import json

app = Flask(__name__)

todos = [{
    "label": "My first task",
    "done": False
}]


@app.route('/todos', methods=['GET'])
def hello_world():
    json_text = jsonify(todos)
    return json_text


@app.route('/todos', methods=['POST'])
def add_new_todo():
    request_body = json.loads(request.data)
    todos.append(request_body)
    json_data = jsonify(todos)

    return json_data
   

@app.route('/todos/<int:position>', methods=['DELETE'])
def delete_todo(position):
    print("This is the position to delete: ", position)
    for i in range(len(todos)):
        if i == position:
            del todos[i]
            return jsonify(todos)



if __name__ == "__main__":
    app.run(
        host='0.0.0.0',
        port=3245,
        debug=True
    )