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:

  1. Create two files in the new folder. They represent two communication services: OrderResource.js and ProductResource.js.
  2. Open the ProductResource.js file and define basic CRUD operations as follows:
    var ProductResource = (function () { function all() {} function get(id) {} function create(product) {} ...

Get KnockoutJS Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.