“Axios Post” Kod odpowiedzi

Jak wysłać nagłówek w Axios

const username = ''
const password = ''

const token = Buffer.from(`${username}:${password}`, 'utf8').toString('base64')

const url = 'https://...'

axios.post(url, {
  headers: {
    'Authorization': `Basic ${token}`
  }
})
Creepy Copperhead

Axios

npm i axios
Hurt Herring

Axios Post

const axios = require('axios');
axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
Gleaming Goat

Axios Post

axios.post('https:sample-endpoint.com/user', {
    Name: 'Fred',
    Age: '23'
  })
  .then(function (response) {
    console.log(response);
  })
Kind Kitten

Axios Post

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
  
 #Performing multiple concurrent requests
  function getUserAccount() {
  return axios.get('/user/12345');
}

function getUserPermissions() {
  return axios.get('/user/12345/permissions');
}

Promise.all([getUserAccount(), getUserPermissions()])
  .then(function (results) {
    const acct = results[0];
    const perm = results[1];
  });
Irfan

Axios Post

try {
			const response = await axios.post('https://movie-app-3073.herokuapp.com/login/', {
				Username: username,
				Password: password
			});
			const data = response.data;
			props.onLoggedIn(data);	
		} catch (error) {
			console.log('This user cannot be found');
		}
Quaint Quelea

Odpowiedzi podobne do “Axios Post”

Pytania podobne do “Axios Post”

Więcej pokrewnych odpowiedzi na “Axios Post” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu