HTTP request wrapper for the yr.no/api.met.no weather service API with support for streams.
npm install yr.no-interface --save
All of these are in the /examples folder of this project.
const yrno =request:timeout: 25000;yrno;
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 = ;const path = ;const yrno =request:timeout: 25000;// response data will be written to a file called res.xml in the// directory this script is being run fromconst filepath = path;yrno;
This module does not support promises by default. Here's how you could get Promise support:
const Promise = ;// Now all functions will return promises. Can also use a module like "pify"const yrno = Promise;// Note the "Async" added to use teh promise versionyrno
This module exports a single function that must be called to get an API wrapper.
// Get an API wrapper instance with a default request timeout of 25 secondsconst yrno =request:// Can pass anything supported by the request module here.// Passing "qs" or "url" will fail since the module will overwrite themtimeout: 25000;
Returns an API
An instance is an object with functions attached. The functions are listed below.
All functions on an
instance contain the same signature of
yrno.func([params[, callback]), e.g
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.
1.1.0 - Updated API endpoints to match api.met.no - thanks @ktrance.
1.0.1 - Patch for security vulnerability in
1.0.0 - Initial stable release.