Skip to content

Instantly share code, notes, and snippets.

@eyeccc
Created February 13, 2018 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eyeccc/d70ef8d0bceed5d2e677a1db1aa4cb8b to your computer and use it in GitHub Desktop.
Save eyeccc/d70ef8d0bceed5d2e677a1db1aa4cb8b to your computer and use it in GitHub Desktop.
bs-fetch Note
let postSomethingWithFormData = (data) => {
/* suppose your data is a object with several fields. e.g.,
let data = {
"a": "aaa",
"b": 123,
"c": "kerker",
};
*/
let d = Qs.stringify(data);
Js.Promise.(
Fetch.fetchWithInit(
"http://someUrl.com",
Fetch.RequestInit.make(
~credentials=Include,
~headers=
Fetch.HeadersInit.makeWithArray([|
("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8")
|]),
~body=Fetch.BodyInit.make(d),
~method_=Post,
()
)
)
|> then_(Fetch.Response.json)
|> then_((rt) => Js.Promise.resolve(rt))
)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment