Home > Software design >  Correct way to write a params api in node js
Correct way to write a params api in node js

Time:05-18

app.post('/scripts/:freezeId', scriptsView.findAll);

app.post('/scripts/deleteScripts', scriptsView.deleteconfig);

Is the only way the second API needs to write on top of the params API or any other ideas are available in node js

CodePudding user response:

Express tries to match routes in order.

So, typically, the URL /scripts/deleteScripts will match '/scripts/:freezeId' and run scriptsView.findAll. Then scriptsView.findAll will send a response and end the handling of that request.

Now, scriptsView.findAll could special case deleteScripts and call next() instead, but that means scriptsView.findAll has to know about things outside its remit.

Changing the order so '/scripts/deleteScripts', is tested first is clearer.

CodePudding user response:

Instead of app.post you can use app.delete for delete scripts API

  • Related