FLASK REST API returns 400 on POST
From the image [second postman screenshot] it looks like you pass data in query string but create_task()
expects them in request body.
Either replace all occurrences of request.json
with request.args
in create_task()
(to make it work with query params) or leave it as it is and send data in request body.
curl -X POST http://localhost:5000/todo/api/v1.0/tasks \-H "Content-Type: application/json" \-d '{"title":"Learn more flask","description":"its supper fun"}'
Also, take a look at Get the data received in a Flask request.
EDITED
Update your add_todo
to something like
@classmethoddef add_todo(cls, task): new_todo = cls(title=task["title"], description=task["description"], completed=0) db.session.add(new_todo) db.session.commit()
Related: generalised insert into sqlalchemy using dictionary.