Finally, we have the DELETE
request, which is the simplest of the four supported methods. The main difference with the delete
method is that it returns no content, which is the accepted standard with DELETE
requests:
class PostApi(Resource): @marshal_with(post_fields) def get(self, post_id=None): … def post(self, post_id=None): … def put(self, post_id=None): … def delete(self, post_id=None): if not post_id: abort(400) post = Post.query.get(post_id) if not post: abort(404) args = post_delete_parser.parse_args(strict=True) user = verify_auth_token(args['token']) if user != post.user: abort(403) db.session.delete(post) db.session.commit() return "", 204
$ curl -X DELETE\ -d "token=<the token>"\ http://localhost:5000/api/post/102
If everything is successfully deleted, you should receive a 204...