Skip to content

Instantly share code, notes, and snippets.

@jrichardsz
Created December 20, 2023 20:34
Show Gist options
  • Save jrichardsz/1e9bb8abf132ee770de4a8fd9e3d5a43 to your computer and use it in GitHub Desktop.
Save jrichardsz/1e9bb8abf132ee770de4a8fd9e3d5a43 to your computer and use it in GitHub Desktop.
Axios snippets

promises

const headers = {
  'Content-Type': 'application/json',
  'Authorization': 'JWT fefege...'
}

axios.post(Helper.getUserAPI(), data, {
    headers: headers
  })
  .then((response) => {
    console.log(response.data)
  })
  .catch((error) => {
    dispatch({
      type: ERROR_FINDING_USER
    })
  })

await

const headers = {
  'Content-Type': 'application/json',
  'Authorization': 'JWT fefege...'
}

var data = {name: "acme-web", "private": true};

//same for put
var response = await axios.post("https://api.github.com/orgs/acme/repos", data, {headers: headers});
console.log(response.status)
console.log(response.data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment