Closed avrobullet closed 4 years ago
You can use a proxy to make requests. But I did consider wildcard * for CORS ~ how are you planning on using this API?
I am currently looking for another COVID19 API that has frequent updates on provincial Canadian statistics, and I found your API's documentation on Postman. I want to use your API for my Canadian COVID19 personal project to replace another API that hasn't updated since May.
As for the accessing the API, I was creating a simple request through XMLHttpRequest() as follows that had worked with the previous API I was using:
var request = new XMLHttpRequest()
request.open('GET', covid19_urls[0], true)
request.onload = function() {...//JSON parsing code here...}
The request won't work as the browser enforces CORS whereas Postman does not. You can get around this by adding a proxy script on your server (looks like you're running PHP/WordPress) — your request would go to the script which in turn is fetching data from the API.
More info on CORS: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
Thanks! I'll give it a shot this weekend.
Did you have any luck, @avrobullet? I'm trying to get around the CORS problem on a Next.js project but am having no luck.
Request access to __https://api.covid19tracker.ca/reports?fill_dates&stat=&date&after&before__ is blocked by CORS policy.