Created
April 26, 2019 08:33
-
-
Save eyeccc/4a915eca01746d8f181451f97a996a2c to your computer and use it in GitHub Desktop.
FormDataExample2.re
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
[@bs.new] external makeFormData: unit => Fetch.formData = "FormData"; | |
[@bs.send] | |
external appendFormData: (Fetch.formData, string, string) => unit = "append"; | |
let formData = makeFormData(); | |
appendFormData(formData, "field1", "value1"); | |
appendFormData(formData, "field2", "value2"); | |
appendFormData(formData, "field3", "value3"); | |
let someRequest = bodyFormData => | |
Js.Promise.( | |
Fetch.fetchWithInit( | |
"https://backend.api.server", | |
Fetch.RequestInit.make( | |
~method_=Post, | |
~credentials=Include, | |
~body=Fetch.BodyInit.makeWithFormData(bodyFormData), | |
(), | |
), | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment