forked from therebelslides/2015-unn-requests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunirest.js
More file actions
32 lines (27 loc) · 746 Bytes
/
unirest.js
File metadata and controls
32 lines (27 loc) · 746 Bytes
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
var unirest = require('unirest');
// Documentation: http://unirest.io/nodejs.html
// GET
unirest.get('http://httpbin.org/get?hello=world')
.headers({
'Accept': 'application/json',
'Custom-Header':'totes works'
})
.end(function (response) {
if(response.error){
console.log('ERROR',response.error);
}
console.log('GET response',response.body, typeof response.body);
});
// POST
unirest.post('http://httpbin.org/post')
.headers({
'Accept': 'application/json',
'Custom-Header':'totes works'
})
.send({"hello":"world"})
.end(function (response) {
if(response.error){
console.log('ERROR',response.error);
}
console.log('POST response',response.body, typeof response.body);
});