-
Notifications
You must be signed in to change notification settings - Fork 13
/
demo.js
27 lines (24 loc) · 931 Bytes
/
demo.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
const client = require('./index')('XXX'); // XXX being your api key found at: https://www.bigdatacloud.com/account
/*
* All api endpoints can be accessed via magic methods in the following camelised format:
* method | endpoint
* For example: an asynchronous "GET" call to the "ip-geolocation-full" endpoint would be: client.getIpGeolocationFull();
* All endpoints return a promise
*/
//Asynchronous example using 'then':
client
.getIpGeolocationFull({ip:'8.8.8.8'})
.then(jsonResult => {
console.log('Asynchronous "then" result:',jsonResult);
}).catch(exception => {
console.log(exception);
});
//Asynchronous example using 'await':
(async () => {
try {
var jsonResult = await client.getIpGeolocationFull({ip:'8.8.8.8'});
console.log('Asynchronous "await" result:',jsonResult);
} catch (error) {
console.error('Asynchronous "await" error:', error);
}
})();