“Cómo usar Axios” Código de respuesta

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

// npm install axios
const axios = require('axios');

// Make a request for a user with a given ID
axios.get('/user?ID=12345')
  .then(function (response) {
    // handle success
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed
  });

// Optionally the request above could also be done as
axios.get('/user', {
    params: {
      ID: 12345
    }
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  })
  .then(function () {
    // always executed
  });  

// Want to use async/await? Add the `async` keyword to your outer function/method.
async function getUser() {
  try {
    const response = await axios.get('/user?ID=12345');
    console.log(response);
  } catch (error) {
    console.error(error);
  }
}
code fighter

Axios reaccionar

$ npm install react-axios
Victorious

Cómo usar Axios Get

const req = async () => {
  const response = await axios.get('https://dog.ceo/api/breeds/list/all')
  console.log(response)
}
req() // Calling this will make a get request and log the response.
Grotesque Gaur

Cómo usar Axios

const [data, setData] = useState([]);
  const getApi = async () => {
    const url = await axios.get(
      "http://quencies.alshumaal.com/api/RCAs/getallRcas.php"
    );
    setData(url.data.getallRCAs);
  };
  useEffect(() => {
    getApi();
  }, []);
Blue Baboon

Respuestas similares a “Cómo usar Axios”

Preguntas similares a “Cómo usar Axios”

Más respuestas relacionadas con “Cómo usar Axios” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código