Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I access the body from HTTP delete in Flask?

I have this method in my Flask WEB API, that receive a list of IDs.

@app.route("/delete_item", methods=['DELETE'])
def delete_item():
    items = request.get_json()
    print(items)
    my_class.delete(items)
    return make_response()

When I call this method, the request.get_json() return None. I am calling it using AngularJS, as bellow:

var data = ['0', '1'. '2']
$http.delete('base_url/delete_item', {data});

How can I access the body in delete http request? The others methods (GET, PUT and POST) are working well.


1 Answers

the docs say:

get_json(force=False, silent=False, cache=True)

Parse data as JSON.

If the mimetype does not indicate JSON (application/json, see is_json), or parsing fails, on_json_loading_failed() is called and its return value is used as the return value. By default this raises a 415 Unsupported Media Type resp.

So from this you will either have to:

  1. Set mimetype to applicatation/json
  2. Set the force parameter to true
like image 144
Jonathan R Avatar answered Nov 06 '25 18:11

Jonathan R



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!