Created
November 16, 2018 23:22
-
-
Save justsml/716c4534ef4afb22f65d4fc4367c7136 to your computer and use it in GitHub Desktop.
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
postFormData('http://example.com/api/v1/users', {user: 'Mary'}) | |
.then(data => console.log(data)) | |
function postFormData(url, data) { | |
return fetch(url, { | |
method: 'POST', // 'GET', 'PUT', 'DELETE', etc. | |
body: new URLSearchParams(data), | |
headers: new Headers({ | |
'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8' | |
}) | |
}) | |
.then(response => response.json()) | |
.catch(error => console.error(error)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment