Skip to content

Instantly share code, notes, and snippets.

@harrisonmalone
Last active June 1, 2019 02:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harrisonmalone/9acccbb0091d5471542ecf4f5b93d5c8 to your computer and use it in GitHub Desktop.
Save harrisonmalone/9acccbb0091d5471542ecf4f5b93d5c8 to your computer and use it in GitHub Desktop.
axios lecture for m0119
// 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