# TEAM CHIN - Node week 2

---
## What we made
**Ever pondered over the current price of gold? In the market for some cattle? Look no further...**
Making an API CALL from the back end.
---
## Goals:
* We used 1 API CALL made from the back-end using the Request module
* We tested- supertest!
* Hosted our project on Heroku and we used Travis!!
* Used module.exports
* We built a good server file structure
* Some Error Handling.
---
## Stretch Goals
- [ ]Display data for a few historical points
- [x]Graphics/SVGs
- [ ] Convert currency
---
## Code Snippets
**Loading animation**
```js=
let loadingAnimation = document.createElement('iframe');
loadingAnimation.setAttribute("src", "public/bounce.html");
priceContainer.appendChild(loadingAnimation);
priceContainer.style.backgroundImage = "none";
priceContainer.style.backgroundColor = "grey";
xhr.onreadystatechange = () => {
if(xhr.readyState === 4 && xhr.status === 200) {
response = JSON.parse(xhr.responseText);
priceContainer.removeChild(loadingAnimation);
let span = document.createElement('span');
span.textContent = response;
span.classList.add('price-span');
priceContainer.appendChild(span);
```
---
**API call**
```js=
const myRequest = (url, cb) => {
https.get(url, (responseFromAPI) => {
let statusCode = responseFromAPI.statusCode
let body='';
responseFromAPI.on('data', (chunk) => {
body+=chunk;
})
responseFromAPI.on('end', () => {
let responseObj = {};
responseObj.body=JSON.parse(body);
responseObj.statusCode=statusCode;
if(statusCode !== 200)
{
cb(new TypeError("StatusCode is not 200, request failed"))
}
else
{
cb(null, JSON.stringify(responseObj))
}
})
})
}
```
---
## What we struggled with
- Time!!! :calendar:
- API call - very slow :watch:
- Retrieving the quantity from the API
---
## What we learned
- Some CSS animation :nail_care:
- How to make a call from the back-end :satisfied:
- How to use Travis
---
## How we worked together
We worked very well.
Someone said "I never been so stress free during a project"
---
stress freeeeeeeeee

{"metaMigratedAt":"2023-06-14T23:12:30.348Z","metaMigratedFrom":"Content","title":"TEAM CHIN - Node week 2","breaks":true,"contributors":"[{\"id\":\"9104740e-93f1-43ef-8caa-fbefca57d972\",\"add\":991,\"del\":395},{\"id\":\"6d4d3154-b883-4d43-b76c-2e58b74a5e3d\",\"add\":1845,\"del\":82}]"}