# DarkSky API
DarkSky (formerly forecast.io) is a great weather data API. To use it you need to register as a developer with the website.
https://darksky.net/dev/register - register here.
Once you have registered then you will be able to make up to 1000 calls per day to the API for free.
After logging in, you will see a page that looks like this. The important thing on this page is the Secret Key. This image shows an old version of my key. You will get a unique key that is valid for your account. You will need that key for every call you make to the API.
A basic call to the API consists of a URL with the endpoint for the API, your secret key, and a latitude and longitude.
Eg: https://api.darksky.net/forecast/[your secret key here]/37.8267,-122.4233
This page has an example of the JSON response you get back. - https://darksky.net/dev/docs/forecast
The key, latitude, and longitude are the required parameters.
There are also several optional parameters. All the optional parameters must be added as query string parameters.
https://api.darksky.net/forecast/[your secret key here]/37.8267,-122.4233?units=ca&lang=de
This example has set the language as German (de - Deutsch) and the units for reporting the data as Canadian (metric).
Another optional parameter is "excludes". It is used to remove some of the blocks from the response, which reduces the size of the returned data and speeds things up and makes it easier to cache results.
API endpoint needs API key to work
# Important Notes
Currently, DarkSky does NOT allow CORS requests from the browser.
You can place the URL for the call you want to make in the location bar of your browser to view the data.
However, if you want to get the data to your JavaScript then you need to:
Use a CURL call from a PHP page to pass the data from DarkSky back to your JavaScript. The PHP CURL call must reside on the same server as your JavaScript.