0

According to this example:

ROUTE('GET /api/users/', action);
ROUTE('POST /api/users/', action);

in the body of function action how we can find out get or post request has been called so that write appropriate code?

Pourya8366
  • 3,424
  • 4
  • 21
  • 28

1 Answers1

1

You might pass a function that calls action with another argument that indicates which method was used:

ROUTE('GET /api/users/', function(...args) { action.call(this, 'GET', ...args) });
ROUTE('POST /api/users/', function(...args) { action.call(this, 'POST', ...args) });

With this, the first argument passed to action will be the method used, and the rest of the arguments will be the ones that the ROUTE callback would receive normally.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320