Skip to content

Instantly share code, notes, and snippets.

@reganstarr
Created March 31, 2016 18:15
Show Gist options
  • Save reganstarr/eebfe210892f50ffee9268e9afd9ef30 to your computer and use it in GitHub Desktop.
Save reganstarr/eebfe210892f50ffee9268e9afd9ef30 to your computer and use it in GitHub Desktop.
var apiUrl = 'ENTER_THE_API_URL_HERE';
var data = JSON.stringify({
"key1": "value1",
"key2": "value2"
});
fetch(apiUrl, {
method: 'POST',
body: data,
headers: {
'Content-Type': 'application/json'
}
})
.then(function(res) {
return res.json(); // You might need to change this to res.text() depending on what type of response you expect.
})
.then(function(body) {
var output = body; // This must be a single object or an array of objects
callback(null, output);
})
.catch(callback);
@aminraisy
Copy link

aminraisy commented Jul 1, 2016

hi @reganstarr thanks alot ... I want to send a photo file (fetching from my google drive) in multipart-form/data with that HTTP API request... would you plz help me how to change this code to do that ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment