bs-hyperquest
v0.5.0
Published
BuckleScript bindings for Substack's hyperquest (http-client) library.
Downloads
3
Readme
bs-hyperquest
BuckleScript bindings for substack's hyperquest library.
Usage
Standard Event Interface
GET
let result =
Js.Promise.make((~resolve, ~reject) =>
Hyperquest.get(~uri, ())
|. Hyperquest.on(
`response(
res => {
let data = ref("");
res
|. Hyperquest.IncomingMessage.on(
`data(
b => data := data^ ++ Hyperquest.Buffer.toString(b),
),
)
|. Hyperquest.IncomingMessage.on(
`error(exn => reject(. exn)),
)
|. Hyperquest.IncomingMessage.on(
`end_(_ => resolve(. data^)),
)
|. ignore;
},
),
)
|. ignore
);
reason-future Interface
GET
Hyperquest.Future.get(~uri, ())
|. Future.mapOk(((_, data)) => data)
|. Future.mapError(res =>
switch(res) {
| (_, `error(exn)) => exn |. Js.String.make |. fail |. finish
| (_, `response(data)) => data |. fail |. finish
}
)
|. ignore