-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproducts_client.js
39 lines (34 loc) · 1.01 KB
/
products_client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var restify = require('restify');
var server = require('server');
var client = restify.createJsonClient({
url: 'http://localhost:3000'
});
// a static product to CREATE READ UPDATE DELETE
var testProduct = {
id: "1",
name: "Apple iPad AIR 2",
os: "iOS 7, upgradable to iOS 7.1",
chipset: "Apple A7",
cpu: "Dual-core 1.3 GHz Cyclone (ARM v8-based)",
gpu: "PowerVR G6430 (quad-core graphics)",
sensors: "Accelerometer, gyro, compass",
colors: "Space Gray, Silver"
};
client.post('/product', testProduct, function (err, req, res, product) {
if (err) {
console.log("An error ocurred >>>>>>");
console.log(err);
} else {
console.log('Product saved >>>>>>>');
console.log(product);
}
});
client.get('/products', function (err, req, res) {
if (err) {
console.log("An error ocurred while getting products >>>>>>");
console.log(err);
} else {
console.log('Products retrieved >>>>>>>');
console.log(res);
}
});