- No additional setup required
- Axios | GET Request - restcountries part (45 min)
- Break 1 (10 min)
- Axios | GET Request - stock-chart part (30 min)
- Break 2 (10 min)
- Recap (10 min)
- LAB | Financial data graphing (GET only) (75 min + HW)
- [EXTRA] Google maps
Students will learn about Axios GET request and how to fetch data from the 3rd party APIs.
After today's class, students will be able to:
- know how to use Axios library to make HTTP GET requests to the 3rd party APIs,
- be able to use data received from web APIs in your app.
Lesson 1: AXIOS | GET Request
- Sample Code provided below
- Axios is a promise-based HTTP client for JS which can be used in the frontend (in browsers) and backend (Node) applications.
- Install via NPM
npm i axios
or using CDN<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
- A standard Axios call for any HTTP request is a method
axios()
that receives a JavaScript object that specifies different options of the request.
axios({
method: 'The HTTP method (verb) we are going to use, e.g. GET, POST, PUT, etc.',
url: 'The url the server is going to receive.',
params: 'URL parameters to be sent with the request'
})
.then(response => {
// Here we can do something with the response object
})
.catch(err => {
// Here we catch the error
});
- Mostly, we will be using a bit shorter and cleaner syntax:
axios.get(url)
.then(reponseFromApi => /* do something with response */)
.catch(error => /* do something with the error */)
- restcountries api example - sample code
- explain available endpoints (one or two),
- then explain the Postman and how to use it,
- then develop code example.
-
Exercise (from the lesson): Try to get the information hitting the endpoint that returns a response based on the currency that’s officially being used.
Review, Q&A, and takeaways.
- Students will practice in the lab.
Review, Q&A, and takeaways.
At a high-level review:
- Axios library allows us to handle asynchronous JS calls to servers. Axios make the promise-based HTTP requests to any server. This server could be our server or any remote server.
- The GET Axios request:
axios.get(endpointUrl)
. - Axios allow us to update DOM without refreshing the page.
LAB | Financial data graphing (GET only) (75 min + HW)
-
[remote] individual
-
[in-class] individual