3

From Nicola's SO answer here and my own testing it seems clear that Eve does not support conditional deletes at resource endpoints.

I know I could use a GET: "where={...}" request to the _ids and _etags of the documents I would like to delete, and then send out a series of requests at each item endpoint to delete them with the If-Match header appropriately set to each item's _etag:

for each item:
    DELETE: http://localhost:5000/items/<item._id>

...but I would like to avoid sending out multiple HTTP requests if possible.

One solution may be predefined database filters, but these would be static filters where I'd like to dynamically filter deletion depending on some URL parameters. Pre-event hooks may be the solution I'm seeking.

Does Eve support bulk deletion? And if not, what is the recommended way to extend Eve's functionality to provide conditional and/or bulk deletes?

Community
  • 1
  • 1

1 Answers1

0

I added a pre-event hook to DELETE, and this seems to be working with the tests I've run so far:

def add_delete_filters(resource, request, lookup):
    if 'where' in request.args:
        conditions = request.args.getlist('where')
        for cond_str in conditions:
            cond = json.loads(cond_str)
            for attrib in cond:
                lookup[attrib] = cond[attrib]

app = Eve()
app.on_pre_DELETE += add_delete_filters