Skip to content

Instantly share code, notes, and snippets.

@xgqfrms-GitHub
Created June 1, 2017 07:52
Show Gist options
  • Save xgqfrms-GitHub/2e9c64cdd8e8522cb1d3261d2105b3cb to your computer and use it in GitHub Desktop.
Save xgqfrms-GitHub/2e9c64cdd8e8522cb1d3261d2105b3cb to your computer and use it in GitHub Desktop.
Axios & Promise & Ajax & Fetch

axios & promise & Ajax & Fetch

$ npm install axios

Promise based HTTP client for the browser and node.js

用于浏览器和node.js的基于Promise的HTTP客户端

https://www.npmjs.com/package/axios

https://github.com/mzabriskie/axios/

react-draggable

https://github.com/mzabriskie/react-draggable

https://mzabriskie.github.io/react-draggable/

https://mzabriskie.github.io/react-draggable/example/

demo

https://github.com/searsaw/react-weather-app

https://scotch.io/courses/getting-started-with-react/setting-up-the-dev-environment?autoplay=true

youtube

Getting Started With Axios (Accessing REST Web Services / HTTP APIs in JavaScript)

https://www.youtube.com/watch?v=1vbpBDWu1AQ

Create A REST API With JSON Server

https://www.youtube.com/watch?v=x3NAo8zqdmo

AJAX to External API - Vue.js 2.0 Fundamentals (Part 10)

https://www.youtube.com/watch?v=KT-yhTnIf_k

@xgqfrms-GitHub
Copy link
Author

parsed json

json = response.json();

fetch(`https://api.github.com/users/xgqfrms/repos`)
.then(function(response) {
    let json = response.json();
    console.log(`response = ${json}`);
    return json;
})
.then(function(json) {
    console.log('parsed json: ', json)
});




fetch(`https://api.github.com/users/xgqfrms/repos`, {
    method: 'get',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    }
})
.then(function(response) {
    return response.json();
    // json() ???
})
.then(function(json) {
    console.log('parsed json: ', json)
})
.catch(function(error) {
    console.log('parsing failed: ', error)
});

@xgqfrms-GitHub
Copy link
Author

xgqfrms-GitHub commented Jun 10, 2017

 fetch(`https://api.github.com/users/xgqfrms/repos`)
.then(function(response) {
    let json = response.json();
    console.log(`response = ${json}`);
    return json;
})
.then(function(json) {
    console.log('parsed json: ', json);
    console.log('parsed json: ', json[0]);
    console.log('parsed json: ', json[1].name);
});



 fetch(`https://api.github.com/users/xgqfrms/repos`)
.then(function(response) {
    let json = response.json();
    console.log(`response = ${json}`);
    return json;
})
.then(function(json) {
    console.log('parsed json: ', json);
    console.log('parsed json: ', json[0].owner);
    console.log('parsed json: ', json[1].name);
});

@xgqfrms-GitHub
Copy link
Author

fetch(`https://api.github.com/users/xgqfrms/repos`, {
    method: 'get',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    }
})
.then(function(response) {
    return response.json();
    // json() ???
})
.then(function(json) {
    console.log('parsed json: ', json);
    console.log('parsed json: ', json[0]);
    console.log('parsed json: ', json[1].name);
})
.catch(function(error) {
    console.log('parsing failed: ', error);
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment