Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrección de error ortográfico en app.py #107

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from flask import Flask, jsonify, request

app = Flask(__name__)

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

# Endpoint GET para obtener la lista de todos
@app.route('/todos', methods=['GET'])
def get_todos():
return jsonify(todos)

# Añadir un nuevo todo
@app.route('/todos', methods=['POST'])
def add_new_todo():
request_body = request.json # Decodifica el cuerpo de la solicitud en un diccionario
print(request_body)
todos.append(request_body) # Agrega el nuevo TODO a la lista de todos
return jsonify(todos)

# Eliminar un todo por posición
@app.route('/todos/<int:position>', methods=['DELETE'])
def delete_todo(position):
try:
todos.pop(position) # Intenta eliminar el todo en la posición dada
return jsonify(todos)
except IndexError:
# Maneja el error si la posición está fuera del rango de la lista
return jsonify({"error": "Posición fuera de rango"}), 404

# Código para ejecutar la aplicación Flask
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3245, debug=True)

# Título: "Corrección de error ortográfico en app.py"

# Descripción: "Corrección de 'GOT' a 'GET' en el comentario de la función que obtiene los todos."