Last active
November 9, 2022 17:55
-
-
Save joshuaquek/c259497db73d596517522c1820f480a6 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
Summary: Some code for making AJAX requests from a NodeJs server or from the browser (React/Vue/Angular) via the Axios node npm module. |
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
axios({ | |
method: 'post', | |
url: 'http://google.com', | |
headers: { | |
'Content-Type': ' application/json' | |
}, | |
data: { | |
'username': 'theUsernameHere1234', | |
'password': 'thePasswordHere1234', | |
} | |
}).then((response) => { | |
console.log(response) | |
}).catch(error => console.log(error.response.data)) |
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
// Assuming that this is within an async function... | |
try{ | |
let response = await axios({ | |
method: 'post', | |
url: 'http://google.com', | |
headers: { | |
'Content-Type': ' application/json' | |
}, | |
data: { | |
'username': 'theUsernameHere1234', | |
'password': 'thePasswordHere1234', | |
} | |
}) | |
} catch(error){ | |
console.log(error.response.data) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Full Axios Cheat Sheet