-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.js
35 lines (27 loc) · 914 Bytes
/
example.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
var http = require('./HTTPClient');
http.get('http://jsonplaceholder.typicode.com/posts/1').then(function(result){
console.log('get:', result);
});
// create new post
var newPost = {
"userId": 1,
"title": "post title",
"body": "post body"
};
var newPostId = http.post('http://jsonplaceholder.typicode.com/posts',newPost).then(function(result){
console.log('post:', result);
return result.id;
});
// update new post
newPost.body = 'foo';
newPostId.then(function(id){
http.put('http://jsonplaceholder.typicode.com/posts/'+id,newPost).then(function(result){
console.log('put:', result);
});
});
// make an invalid request that results in rejected promise
http.put('http://jsonplaceholder.typicode.com/posts/foo',newPost).then(function(result){
console.log('put foo:', result);
}, function(error){
console.log('put foo failed with status code', error.statusCode);
});