Last active
June 1, 2019 02:32
-
-
Save harrisonmalone/9acccbb0091d5471542ecf4f5b93d5c8 to your computer and use it in GitHub Desktop.
axios lecture for m0119
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
// all of these techniques allow us to do http requests using javascript | |
// fetch | |
// which is built in to javascript and quite popular | |
// xmlhttp | |
// old school | |
// jquery | |
// old school but still used | |
// axios | |
// the most modern way to do http requests | |
const axios = require("axios") | |
axios.get("https://reqres.in/api/users?page=2") | |
.then((response) => { | |
console.log(response.data.data) | |
}) | |
axios.get("https://reqres.in/api/users/2") | |
.then((response) => { | |
console.log(response) | |
}) | |
// the .catch handles the error | |
.catch((error) => { | |
// if (error.message === "something") { | |
// render 404 | |
// } | |
console.log(error.message) | |
}) | |
const morpheus = { | |
name: "morpheus", | |
job: "leader" | |
} | |
axios.post("https://reqres.in/api/users", morpheus) | |
.then((response) => { | |
console.log(response.data) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment