Solution 1
curl -X POST http://127.0.0.1:5000/todo/api/v1.0/createTask
curl -X POST -d '{"title": "AAA", "description": "AAADESCRIPTION"}' -H 'Content-Type: application/json' http://127.0.0.1:5000/todo/api/v1.0/createTask
# @app.route('/todo/api/v1.0/createTask', methods=['POST', 'GET'])
@app.route('/todo/api/v1.0/createTask', methods=['POST'])
def create_task():
request_params = request.get_json()
if not request_params or 'title' not in request_params:
abort(400)
task = {
'id': tasks[-1]['id'] + 1,
'title': request_params['title'],
'description': request_params.get('description', ""),
'done': False
}
tasks.append(task)
return jsonify({'task': task}), 201
Solution 2
methods = ["GET", "POST"]
if request.method == "post":
your code here
else:
return render_template("createtasks")