I successfully implemented 4 serverless routes
- /api/list (GET)
- /api/add (POST)
- /api/update/:id (PUT)
- /api/remove/:id (DELETE)
These routes were added to the api/now.json file in the following format:
{"src": "/api/list", "dest": "./list.js", "methods": ["GET"]},
{"src": "/api/add", "dest": "./add.js", "methods": ["POST"]},
{"src": "/api/update/*", "dest": "./update.js", "methods": ["PUT"]},
{"src": "/api/remove/*", "dest": "./remove.js", "methods": ["DELETE"]}
Currently, the /api/list and /api/add routes that do not require parameters are functioning correctly. However, I am facing issues with the /api/update and /api/remove routes, likely due to incorrect usage of regex on the api path within the now.json file.
The snippet for handling the update route is as follows:
app.put('/api/update/:id', (req, res) => {
...
});
module.exports = app;