Sapper: Support DELETE requests

Created on 9 Jan 2018  路  6Comments  路  Source: sveltejs/sapper

I imagine (though I'm not sure) that Sapper supports all of the request types that express supports, but trying to export a DELETE handler currently won't work because delete is a reserved keyword, so export function delete(){} won't work.

Is there a clever workaround to trick js into letting me use delete? If not, could we add one to Sapper?

I thought maybe webpack harmony magic would let this work, but it doesn't seem to:

export default {
    delete(req, res) {
        console.log('delete');
    }
};

Thanks! And great work as always, Sapper is fun.

Most helpful comment

Released 0.4 with export function del(...){...} support thanks to @EmilTholin

All 6 comments

Wouldn't you need to do this?

export function delete(req, res) {
 // 
}

In CJS terms, your example would be available as exports.default.delete when you want exports.delete.

That's right @lukeed, but what you have written throws Module parse failed: Unexpected token because delete is a reserved keyword.

I think most people handle this by using _delete, del, remove or destroy. Other more colorful options include annihilate, smash, crush.

good point! I think del is probably the best option here:

export function del(req, res) {
  // ...
}

Any objections?

Seems like the best option to me!

Released 0.4 with export function del(...){...} support thanks to @EmilTholin

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nolanlawson picture nolanlawson  路  4Comments

matt3224 picture matt3224  路  4Comments

BMorearty picture BMorearty  路  3Comments

freedmand picture freedmand  路  4Comments

Rich-Harris picture Rich-Harris  路  3Comments