dark-sky-api
Based on Elias Hussary's dark-sky.
A wrapper library for Dark Sky API (previously known as Forecast.io). See Dark Sky developer docs: https://darksky.net/dev/docs.
Install it
npm install dark-sky-api
Require it
import darkSkyApi from 'dark-sky-api';
Initialize it
While dark-sky-api allows embedding api keys through use of jsonp on the backend using a proxy to make the api call is highly suggested as this hides the API key from client side requests ref.
- proxy url is optional *
- pass an empty string or false for api key if using proxy url *
const darkSky = new darkSkyApi('your-dark-sky-api-key', '//base-url-to-proxy/service');
Use it
darkSky.latitude(lat)
.longitude(long)
.get();
.then(data => console.log(data));
Feel free to omit setting of latitude and longitude for subsequent calls i.e.:
const darkSky = new darkSkyApi('your-dark-sky-api-key');
darkSky.latitude(lat)
.longitude(long);
darkSky.get();
Make use of excludes
"Exclude some number of data blocks from the API response. This is useful for reducing latency and saving cache space (see 'Request Parameters')."
const excludes = ['alerts', 'currently', 'daily', 'flags', 'hourly', 'minutely'],
exludesBlock = excludes.filter(val => val != 'currently').join(',')
darkSky.latitude(lat)
.longitude(long)
.exclude()
.get()
.then(data => console.log(data));