Here is the code I am looking at (it makes a HTTP request)
const https = require('https');
https.get('https://jsonplaceholder.typicode.com/users', res => {
let data = [];
const headerDate = res.headers && res.headers.date ? res.headers.date : 'no response date';
console.log('Status Code:', res.statusCode);
console.log('Date in Response header:', headerDate);
res.on('data', chunk => {
data.push(chunk);
});
res.on('end', () => {
console.log('Response ended: ');
const users = JSON.parse(Buffer.concat(data).toString());
for(user of users) {
console.log(`Got user with id: ${user.id}, name: ${user.name}`);
}
});
}).on('error', err => {
console.log('Error: ', err.message);
});
So we have to create a Js.Array because the “push” modifies in place. The ReScript documentation for Js.Array is here: Js.Array | ReScript API
I can’t figure out how to create an object of type Js.Array .
I know that afterwards, we can dall Js.Array.push(data, …); but I don’t see how to create a blank Js.Array in the first place.