Last active
August 31, 2017 19:32
-
-
Save doug2k1/ff9ec4dee7ac3ddae164b6d21a6c973e to your computer and use it in GitHub Desktop.
HTTP Post example in JavaScript - https://medium.com/douglas-matoso-english/http-primer-for-frontend-developers-f091a2070637
This file contains hidden or 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
// the request: | |
// POST a new email address to my GitHub account | |
fetch('https://api.github.com/user/emails', { // the URI | |
method: 'POST', // the method | |
body: JSON.stringify(["[email protected]"]) // the body | |
}) | |
.then(response => { | |
// we received the response and print the status code | |
console.log(response.status) | |
// return response body as JSON | |
return response.json() | |
}) | |
.then(json => { | |
// print the JSON | |
console.log(json) | |
}) | |
// on success will log: | |
// 201 | |
// { ... contents of the response body as JSON ... } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment