I'm using Plausible Analytics to get my website data. I'm creating a widget so I can view my data at a glance and I'm using their API to do so.
I would like to get realtime info as well as the filtering the data so it requires two different urls.
I've created two bits of code to get the data I need but I am duplicating code to do so, I'm sure this will also have an effect on speed.
They're using the same Method and Headers so can I combine these to make a single piece of code?
const reqRealtime = new Request(realtimeURL)
reqRealtime.method = "GET"
reqRealtime.headers={
"Authorization":api,
"Content-Type":"application/json",
}
responseRealtime = await reqRealtime.loadString()
const resultRealtime = JSON.parse(responseRealtime);
console.log(responseRealtime)
const reqStats = new Request(statsURL)
reqStats.method = "GET"
reqStats.headers={
"Authorization":api,
"Content-Type":"application/json",
}
responseStats = await reqStats.loadString()
const resultStats = JSON.parse(responseStats);
console.log(responseStats)