-
Notifications
You must be signed in to change notification settings - Fork 23
/
request_examples.re
59 lines (51 loc) · 1.38 KB
/
request_examples.re
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Simple request */
Js.Promise.(
Axios.get("/user?ID=12345")
|> then_(response => resolve(Js.log(response##data)))
|> catch(error => resolve(Js.log(error)))
);
/* Post requests */
Js.Promise.(
Axios.post("/user")
|> then_(response => resolve(Js.log(response##data)))
|> catch(error => resolve(Js.log(error)))
);
let user = {"username": "michel", "password": "12345678"};
Js.Promise.(
Axios.postData(
"/auth",
{
user;
},
)
|> then_(response => resolve(Js.log(response##data)))
|> catch(error => resolve(Js.log(error)))
);
/* Concurrency */
Js.Promise.(
Axios.all2((Axios.get("/users/1"), Axios.get("/users/1/friends")))
|> then_(((user, friends)) =>
resolve(Js.log2(user##data, friends##data))
)
|> catch(error => resolve(Js.log(error)))
);
/* Headers */
let headers = Axios.Headers.fromObj({"Content-type": "application/json"});
Axios.getc("https://example.com", Axios.makeConfig(~headers, ()));
let headersDict =
Js.Dict.(
{
let dict = empty();
dict->set("Content-type", "application/json");
dict;
}
);
let headers = Axios.Headers.fromDict(headersDict);
Axios.getc("https://example.com", Axios.makeConfig(~headers, ()));
/* Node.js Agent */
let httpsAgent =
Axios.Agent.Https.(config(~rejectUnauthorized=false, ()) |> create);
Axios.getc(
"https://insecure-example.com",
Axios.makeConfig(~httpsAgent, ()),
);