yr.no-interface
![Coverage Status](https://coveralls.io/repos/github/evanshortiss/yr.no-interface/badge.svg?branch=master)
HTTP request wrapper for the yr.no/api.met.no weather service API with support
for streams.
Install
npm install yr.no-interface --save
Examples
All of these are in the /examples
folder of this project.
Callback Example
const yrno = require('yr.no-interface')({
request: {
timeout: 25000
}
});
yrno.locationforecast({
query: {
lat: 53.3478,
lon: 6.2597
},
version: 1.9
}, function (err, xml) {
if (err) {
} else {
}
});
Streaming Example
Streams are one of the most powerful features in node.js. They allow you to
perform I/O while using a tiny amount of memory since they pass data through the
process in small "chunks".
Using streams is useful for certain response types such as the radar
API since
it returns a large GIF file that could use a large amount of the node.js process
memory if loaded into a callback
Below we use a stream to pipe the HTTP respone from the yr.no API to a file on
our machine.
const fs = require('fs');
const path = require('path');
const yrno = require('yr.no-interface')({
request: {
timeout: 25000
}
});
const filepath = path.join(process.cwd(), 'weather.xml');
yrno.locationforecast({
query: {
lat: 53.3478,
lon: 6.2597
},
version: 1.9
})
.pipe(fs.createWriteStream(filepath));
Promises Example
This module does not support promises by default. Here's how you could get
Promise support:
const Promise = require('bluebird');
const yrno = Promise.promisifyAll(
require('yr.no-interface')({
request: {
timeout: 25000
}
})
);
yrno.locationforecastAsync({
query: {
lat: 53.3478,
lon: 6.2597
},
version: 1.9
})
.then((xml) => {
console.log('weather xml is - ', xml);
})
API
module
This module exports a single function that must be called to get an API wrapper.
const yrno = require('yr.no-interface')({
request: {
timeout: 25000
}
});
Returns an API instance
.
instance
An instance is an object with functions attached. The functions are listed
below.
instance.FUNCTION
All functions on an instance
contain the same signature of
yrno.func([params[, callback]), e.g yrno.locationforecast(params, callback)
.
callback is optional. If no callback is provided a stream is returned so you
can use node's stream awesomeness to pass data around. params should contain
the querystring params as specified at the
yr.no docs.
Each request must specify params.version
as the met.no API requires this.
instance functions
- errornotifications
- extremeforecast
- extremesWWC
- forestfireindex
- geosatellite
- gribfiles
- icemap
- locationforecast
- locationforecastlts
- metgm
- mountaineasterobservations
- oceanforecast
- polarsatellite
- probabilityforecast
- radar
- seaapproachforecast
- seasonforecast
- subjectiveforecast
- sunrise
- temperatureverification
- textforecast
- textlocation
- tidalwater
- trondheimsleia
- turbulence
- uvforecast
- weatherformetnosite
- weathericon
- windforecast
CHANGELOG