openweathermap-api-module v0.0.1
openweathermap-api-module
Simple Node module to call the openweathermap API
This wrapper is based on the free tier of OpenWeatherMap API. You can get your API key here.
Table of Contents
Install
$ npm install openweathermap-api-module Usage
const OpenWeatherMapRequests = require('openweathermap-api-module')
const apiKey = 'api key'
const client = new OpenWeatherMapRequests(apiKey)
client.currentWeatherByCityName('boston').then(console.log).catch(console.error)Check out the Openweathermap API documentation for more information!
API
Table of Contents
- constructor
- currentWeatherByCityName
- currentWeatherByCityName
- currentWeatherByCityId
- currentWeatherByGeoCoordinates
- currentWeatherByZipCode
- currentWeatherByRectangleZone
- currentWeatherByCircleZone
- currentWeatherByCityIds
- constructor
- getOneLocationByCityName
- getOneLocationByCityId
- getOneLocationByGeoCoordinates
- getOneLocationByZipCode
- getManyLocationsByRectangleZone
- getManyLocationsByCircleZone
- getManyLocationsByCityIds
constructor
Mixin for handling API requests options
Parameters
Examples
const client = new OpenWeatherMapRequest(ApiKey, {})currentWeatherByCityName
Call Current weather for One location by city Name
Parameters
argsObject Arguments for mixin handler
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByCityName({cityName: 'boston,us'})
client.currentWeatherByCityName({cityName: 'boston,us', lang: 'fr'})Returns Object response - Object with data from request Type
currentWeatherByCityName
Mixin for handling API requests options
Parameters
args
currentWeatherByCityId
Call Current weather for One location by city ID
Parameters
argsObject Arguments for mixin handler
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByCityId({cityId: 2643743})
client.currentWeatherByCityId({cityId: '2643743', units: 'metric'})Returns Object response - Object with data from request Type
currentWeatherByGeoCoordinates
Call Current weather for One location by Geographic Coordinates
Parameters
argsObject Arguments for mixin handler
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByGeoCoordinates({coordinates: { lon:'139.01', lat:'35.02' } })
client.currentWeatherByGeoCoordinates({coordinates: { lon:'139.01', lat:'35.02' }, lang: 'fr' })Returns Object response - Object with data from request Type
currentWeatherByZipCode
Call Current weather for One location by Zipcode
Parameters
argsObject Arguments for mixin handler
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByZipCode({ zipCode: '90247,us' })
client.currentWeatherByZipCode({ zipCode: '90247,us', lang: 'fr' })Returns Object response - Object with data from request Type
currentWeatherByRectangleZone
Call Current weather for many locations by Rectangle Box
Parameters
argsObject Arguments for mixin handler
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByRectangleZone({ bbox: { lonLeft: '12', latBottom: '32', lonRight: '15',
latTop: '37', zoom: '10' } })
client.currentWeatherByRectangleZone({ bbox: { lonLeft: '12', latBottom: '32', lonRight: '15',
latTop: '37', zoom: '10' }, units: 'imperial' })Returns Object response - Object with data from request Type
currentWeatherByCircleZone
Call Current weather for many locations by Circle Radius
Parameters
argsObject Arguments for mixin handler
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherByCircleZone({ circle: { lat: 55.5, lon: 37, cnt: 10 } })
client.currentWeatherByCircleZone({ circle: { lat: 55.5, lon: 37, cnt: 10 }, format: 'html' })Returns Object response - Object with data from request Type
currentWeatherByCityIds
Call Current weather for many locations by City Ids
Parameters
argsObject Arguments for mixin handler
Examples
const client = new OpenWeatherMapRequests(API_KEY)
client.currentWeatherBy({ cityIds: [524901,703448,2643743] })
client.currentWeatherBy({ cityIds: [524901,703448,2643743], lang: 'fr' })Returns Object response - Object with data from request Type
constructor
Current Weather API handler. Key is inherited from OpenWeatherMapRequests
Parameters
apiKeybaseUrlbaseUrl-nullString API base URL from OpenWeatherMap API
Examples
const client = new WeatherApiHandler('Api_key','base_url')getOneLocationByCityName
Call Current weather for One location by city Name
Parameters
Examples
// api.openweathermap.org/data/2.5/weather?q=London
// api.openweathermap.org/data/2.5/weather?q=London,uk
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getLocationByCityName('boston')
client.getLocationByCityName('London,uk')
client.getLocationByCityName('tokyo', { units: 'imperial' })
client.getLocationByCityName('tokyo', { format: 'xml', units: 'imperial', lang='fr' })Returns Object requestResponse - Return Object from API call
getOneLocationByCityId
Call Current weather for One location by ID
Parameters
cityId(String | Number) Id of the Cityargs(optional, default{})optionsObject? options for request
Examples
// api.openweathermap.org/data/2.5/weather?id=2643743
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getLocationByCityId(2643743)
client.getLocationByCityId('2643743')Returns Object requestResponse - Return Object from API call
getOneLocationByGeoCoordinates
Call Current weather for One location by Coordinates
Parameters
coordinatesObject Object including Coordinates. Ex: { lat: 139.01, lon: 35.02 }args(optional, default{})optionsObject? options for request
Examples
// api.openweathermap.org/data/2.5/weather?lat=35&lon=139
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getLocationByGeoCoordinates({lon: 139.01, lat: 35.02})
client.getLocationByGeoCoordinates({lon: 139.01, lat: 35.02}, { format: 'xml' })Returns Object requestResponse - Return Object from API call
getOneLocationByZipCode
Call Current weather for One location by Zip Codes
Parameters
zipCodeargs(optional, default{})zipcodeString Zipcode from Country, ex: 'zipcode,country' (optional, default"90247,us")optionsObject? options for request
Examples
// api.openweathermap.org/data/2.5/weather?zip=94040,us
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getLocationByZipCode('94040,us')Returns Object requestResponse - Return Object from API call
getManyLocationsByRectangleZone
Call current weather data for several cities using a Bounding Box bbox bounding box lon-left,lat-bottom,lon-right,lat-top,zoom
Parameters
bboxObject Bounding Box for location. Example: bbox={ lonLeft: '0', latBottom: '0', lonRight: '0', latTop: '0', zoom: '0' }args(optional, default{})optionsObject? options for request
Examples
// api.openweathermap.org/data/2.5//box/city?bbox=12,32,15,37,10
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getManyLocationsByRectangleZone({ lonLeft: '12', latBottom: '32', lonRight: '15',
latTop: '37', zoom: '10' })
client.getManyLocationsByRectangleZone({ lonLeft: '12', latBottom: '32', lonRight: '15',
latTop: '37', zoom: '10' }, { units: 'metric' })Returns Object requestResponse - Return Object from API call
getManyLocationsByCircleZone
Call current weather data for several cities using a Longitude and Latitude and get all cities around it
Parameters
circleObject Circle object with longitude, latitude and number of cities to show ex: { lat: 55.5, lon: 37, cnt: 10 }args(optional, default{})optionsObject? options for request
Examples
// api.openweathermap.org/data/2.5//box/city?lat=55.5&lon37.5&cnt=10
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getManyLocationsByCircleZone({ lat: 55.5, lon: 37, cnt: 10 })
client.getManyLocationsByCircleZone({ lat: 55.5, lon: 37, cnt: 10 }, { lang: 'fr' })Returns Object requestResponse - Return Object from API call
getManyLocationsByCityIds
Call for several city IDs
Parameters
cityIdsargs(optional, default{})citiIdsArray Array filled with city IDs, ex: 524901,703448,2643743optionsObject? options for request
Examples
// http://api.openweathermap.org/data/2.5/group?id=524901,703448,2643743
const client = new CurrentWeatherHandler(API_KEY, BASE_URL)
client.getManyLocationsByRectangleZone([524901,703448,2643743])
client.getManyLocationsByRectangleZone([524901,703448,2643743], { lang: 'fr' })Returns Object requestResponse - Return Object from API call
7 years ago