json-server
json-server copied to clipboard
Can the POST method return a custom JSON result instead of returning the requested JSON?
Hi there! Can you make the POST method to return a custom JSON result data in db.json not just return the requested JSON data? Thx!
To do this, you need to use middleware, where you will map the POST route so that all transmissions to that URI are returned in the format you want.
`module.exports = function (req, res, next) { const endpointRoutesURI = { 'api/entry-route': require('./my-router-with-return-new-data-post') }
const endpoint = Object.keys(endpointRoutesURI).find((key) =>
req.originalUrl.startsWith(key)
);
// Here you work with the rest of the logic. }