Node client library to allow easy communication with the Magic Seaweed API
You will Need to contact Magic Seaweed in order to get an API key. Please make sure you read their terms first.
See release notes for new release details.
Available on npm. NOTE: Version 2.0.0 is only supported in Node 5+. For versions lower than Node 5 use msw-client v1.4.1
firstly you need to install into your dependencies:
npm install msw-client --save
Constructor, API key and SpotId
Then simply create an instance of the client:
const MSW = ;const MswClient =apikey: 'YOUR_API_KEY'spot_id: 2 // must be a number;
Both apikey and spot_id are required.
spot_id indicates the spot / beach you want to get forecast data for
spot_id: 1449 // this is rest bay
To figure out your spot_id visit the surf report for that beach on the Magic Seaweed website and look at the url:
http://magicseaweed.com/Porthcawl-Rest-Bay-Surf-Report/1449/ - spot id is the last parameter
Once set in the constructor, the spot_id can be retrieved or updated at any point:
MswClient; // 2MswClient; // must be a number
To make a request simply call:
These will respond with an array of objects as documented MSW API
As of version 1.1.0 you can now set the unit to your country region so that measurements and temperature are returned as you would expect in your region.
e.g. temperature returns as F for US requests.
There are three valid unit types: 'uk', 'us' or 'eu'.
You can set units on the constructor:
const MSW = ;const MswClient =apikey: 'YOUR_API_KEY'spot_id: 2 // must be a numberunits: 'us' // must be a string;
or via the setUnits function
MswClient;MswClient; // returns 'us';
If not set it will default to uk
MswClient; // returns 'uk';
You can also add fields to filter the data you want.
This can either be done via the constructor:
const MSW = ;const MswClient =apikey: 'YOUR_API_KEY'spot_id: 2fields: 'timestamp' 'wind' // must be an array;
or at any point in your code via functions:
MswClient; // add single field by string nameMswClient; // add fields by array
You can also retrieve and remove fields:
MswClient; // ['timestamp', 'wind'] returns fields arrayMswClient; // remove single field by string nameMswClient; // I wonder what this does...
A list of fields are available based on the response data. More details here: MSW API
Feel free to submit issues and contribute.