Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

axios async get

const axios = require('axios');

const sendGetRequest = async () => {
    try {
        const resp = await axios.get('https://jsonplaceholder.typicode.com/posts');
        console.log(resp.data);
    } catch (err) {
        // Handle Error Here
        console.error(err);
    }
};

sendGetRequest();
Comment

axios api get request async

async function getUserData() {
	try {
		const response = await axios.get("/user_login/john1904");
		console.log(response);
	}
	catch (error) {
		console.log(error);
	}
}
Comment

axios async await

async fetchCatFacts() {
    await axios.get("//localhost:8082/api_v1/orders", {})
        .then((response) => {

          this.catFacts = response.data.data;
          console.log("resp", response.data);
        });
 Run code snippet
Comment

axios async await

/**
 * Axios : Async/Await
 * Put within method
 */
function fetchSampleData() {
    let method = 'get' // ex. get | post | put | delete , etc
    return axios[method](url,params)
        .then((response) => {
            // success
            //-> save response to state, notification

            return true // pass to finish
        })
        .catch((error) => {
            // failed
            //-> prepare, notify, handle error

            return false // pass to finish
        })
        .then((resultBoolean) => {
            // do something after success or error

            return resultBoolean // for await purpose
        });
}

// Implementation
async function fetchResult() {
    let success = await fetchSampleData()
    if (success) {
        // handle success 
        // #
    } else {
        // handle error
        // #
    }
}
Comment

Javascript axios get async await

const axios = require('axios');

async function doGetRequest() {

  let res = await axios.get('http://webcode.me');

  let data = res.data;
  console.log(data);
}

doGetRequest();
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery remove items from dropdownlist 
Javascript :: how to change tab color react bootstraps customixation 
Javascript :: (intermediate value).getdate is not a function 
Javascript :: cache remove using ajax 
Javascript :: how to get all form values in javascript 
Javascript :: generate random integer javascript 
Javascript :: jquery set width 
Javascript :: vue computed composition api 
Javascript :: for loop condition javascript 
Javascript :: javascript json parse 
Javascript :: js datetime local 
Javascript :: zoom in canvas javascript 
Javascript :: add month date now javascript 
Javascript :: get days in current month using moment.js 
Javascript :: is_int js 
Javascript :: react 17 hot reload not working 
Javascript :: JS append content into a DOM element 
Javascript :: how to change text to italic in javascript 
Javascript :: prop-types install npm 
Javascript :: How to calc() height in react native for styling 
Javascript :: react toastify dark mode 
Javascript :: assign this value or if it is undefined this other value javascript 
Javascript :: if else short term 
Javascript :: fibonacci sums javascript 
Javascript :: control audio javascript 
Javascript :: angular load json file with httpclient 
Javascript :: javascript is number even or odd 
Javascript :: get current time epoch javascript 
Javascript :: jquery await async 
Javascript :: javascript expressions 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =