Setting CRUD operations in the resource
We are going to define some services to define CRUD operations for our products and orders. A common mistake that some developers make is setting CRUD operations within model classes. Best practice says that it is better to separate models and communication layers.
To prepare your project, create a folder called services
. In this folder, store files that will contain CRUD operations. Perform the following steps:
Create two files in the new folder. They represent two communication services:
OrderResource.js
andProductResource.js
.Open the
ProductResource.js
file and define basic CRUD operations as follows:var ProductResource = (function () { function all() {} function get(id) {} function create(product) {} function update(product) {} function remove(id) {} return { all: all, get: get, create: create, update: update, remove: remove }; })();
This is the skeleton of the CRUD service. You use the
all
andget
methods to define...