How to use the Paragonday API.
Our API is currently a wrapper around another sunset times API. This means that we just rely on another API to get the sunrise and sunset times.
Here's an example of fetching the suntimes for the latitude and longtidue of the Index space. You can copy and paste this url into a browser, which is the same as making a GET request.
https://paragonday.herokuapp.com/api/v1/sunrise-sunset/suntime?lat=40.7176017&lng=-73.9997659
View full code example
// Asks the website visitor for their latitude and longitude
// and then pass them to our findTime function
navigator.geolocation.getCurrentPosition(function(position) {
let lat = position.coords.latitude;
let lng = position.coords.longitude;
findTime(lat, lng);
}, function(error) {
console.error("Location Error Code = " + error.code + " - " + error.message);
});
// Our function that calls the API and prints out the response
async function findTime(lat, lng){
let url = 'https://paragonday.herokuapp.com/api/v1/sunrise-sunset/suntime?lat=' + lat + '&lng=' + lng;
let response = await fetch(url).then(res => res.json())
console.log(response);
let sunTime1 = response.time1;
let sunTime2 = response.time2;
// now you can use these variables in your website!
}
There are only a handful of locations available to use this way, because they are hard-coded into the server. I originally made this so that we could put the Paragonday Time of the Playground on the homepage of the paragonday site without having to put our exact latitude and longitude out on the internet.
Available locations:
playground
quay
factory
index
temperance
Here's an example API url.
https://paragonday.herokuapp.com/api/v1/sunrise-sunset/suntime?location=index
// Our function that calls the API and prints out the response
async function findTime(){
let location = 'index';
let url = "https://paragonday.herokuapp.com/api/v1/sunrise-sunset/suntime?location=" + location;
let response = await fetch(url).then(res => res.json())
console.log(response);
}
// Call the function
findTime();