September 2017
Intermediate to advanced
450 pages
11h 24m
English
Our /middleware/rest.js middle already had a means of reading from, and writing to, a generic array-based model store. We have simply updated those places of the application to rely instead on Mongoose's model API to do the same operations. In many ways, this simplifies some of the operations we were previously doing, but the added complexity of the callbacks for the asynchronous requests to the database adds some new nuances to our middleware. The PUT (update), PATCH (modify) and DELETE (delete) HTTP method hooks, in particular, are worth a second look:
... // updatestore.replaceOne({ _id: id }, itemReplace, function(error) { if (error) return res.status(400).json(storeError(error)); res.status(204).send();});... // modify ...Read now
Unlock full access