This repository was archived by the owner on May 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathexamples.js
More file actions
44 lines (35 loc) · 1.27 KB
/
examples.js
File metadata and controls
44 lines (35 loc) · 1.27 KB
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
40
41
42
43
44
// ES6 syntax is used here. Please refer to the link below for importing
// wstrade-api in CommonJS:
// https://github.com/ahmedsakr/wstrade-api/docs#importing-wstrade-api-commonjs-es6
import { headers } from 'wstrade-api';
/**
* The headers module provides you with the extensibility
* to insert custom headers into all requests made to Wealthsimple Trade
* endpoints.
*
* Let's walk through some practical examples.
*/
// If you wanted to explicitly tell Wealthsimple Trade that the content is JSON,
// you can do this by adding this custom header.
// This header is not automatically inserted by wstrade-api network-level code
// as it is not necessary.
headers.add('Content-type', 'application/json');
// Let's print all custom headers.
// We expect the one we just added to be shown.
console.log(headers.values());
// Output:
// [ [ 'content-type', 'application/json' ] ]
// Let's delete the custom header now.
headers.remove('Content-type');
// We now expect this to be an empty list.
console.log(headers.values());
// Output:
// []
// We will now add more than 1 custom header, and invoke
// the headers.clear() API to remove them all.
headers.add('Content-type', 'application/json');
headers.add('device', 'iphone');
headers.clear();
console.log(headers.values());
// Output:
// []