Created
February 13, 2018 08:42
-
-
Save eyeccc/d70ef8d0bceed5d2e677a1db1aa4cb8b to your computer and use it in GitHub Desktop.
bs-fetch Note
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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