-
-
Notifications
You must be signed in to change notification settings - Fork 182
feature: Weather API definition. #1733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
32e2733
Weather API definition.
panaaj 8753432
Expose methods to plugins.
panaaj 235c038
add daily & point forecast endpoints
panaaj c896ade
chore: formatting
panaaj 67d2209
Add ts-auto-guard to WeatherProvider interface.
panaaj 90cd166
Merge branch 'master' into v2_api_weather
panaaj 79931dc
align API conventions
panaaj c0c99c8
Merge branch 'master' into v2_api_weather
panaaj 1e533d3
rebase master
panaaj d441e65
Merge branch 'master' into v2_api_weather
panaaj b3508b4
add docs
panaaj d89900d
Refine API surface
panaaj be0b074
Add support for startDate parameter
panaaj fc3c19c
chore: update docs
panaaj 1f1aba8
chore: docs
panaaj 84c1d2e
Merge branch 'master' into v2_api_weather
panaaj a362c4c
Merge branch 'master' into v2_api_weather
panaaj 1849c77
Merge branch 'master' into v2_api_weather
panaaj 6aafe28
Allow provider targeting in requests.
panaaj 0e08ce7
chore: format
panaaj 4769e79
Merge branch 'master' into v2_api_weather
panaaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| # Weather Provider Plugins | ||
|
|
||
| #### (Under Development) | ||
|
|
||
| _Note: This API is currently under development and the information provided here is likely to change._ | ||
|
|
||
|
|
||
| The Signal K server [Weather API](../rest-api/autopilot_api.md) will provide a common set of operations for retrieving meteorological data and (like the Resources API) will rely on a "provider plugin" to facilitate communication with the autopilot device. | ||
|
|
||
| --- | ||
|
|
||
| ## Provider plugins: | ||
|
|
||
| A weather provider plugin is a Signal K server plugin that implements the **Weather Provider Interface** which: | ||
| - Tells server that the plugin is a weather data source | ||
| - Registers the methods used to action requests passed from the server to retrieve data from the weather provider. | ||
|
|
||
| _Note: multiple weather providers can be registered._ | ||
|
|
||
| The `WeatherProvider` interface is defined as follows in _`@signalk/server-api`_: | ||
|
|
||
| ```typescript | ||
| interface WeatherProvider { | ||
| name: string | ||
| methods: WeatherProviderMethods | ||
| } | ||
| ``` | ||
| where: | ||
|
|
||
| - `name`: The weather ssource name. _(e.g. `'OpenWeather'`, `'Open-Meteo'`)_ | ||
|
|
||
| - `methods`: An object implementing the `WeatherProviderMethods` interface defining the functions to which requests are passed by the SignalK server. _Note: The plugin __MUST__ implement each method, even if that operation is NOT supported by the plugin!_ | ||
|
|
||
| The `WeatherProviderMethods` interface is defined as follows in _`@signalk/server-api`_: | ||
|
|
||
| ```typescript | ||
| interface WeatherProviderMethods { | ||
| getData: (position: Position) => Promise<WeatherProviderData> | ||
| getObservations: ( | ||
| position: Position | ||
| ) => Promise<WeatherData[]> | ||
| getForecasts: (position: Position) => Promise<WeatherData[]> | ||
| getWarnings: (position: Position) => Promise<WeatherWarning[]> | ||
| } | ||
| ``` | ||
|
|
||
| _**Note: The Weather Provider is responsible for implementing the methods and returning data in the required format!**_ | ||
|
|
||
|
|
||
|
|
||
| ### Provider Methods: | ||
|
|
||
| **`getData(position)`**: This method is called when a request to retrieve weather data for the provided position is made. | ||
|
|
||
|
|
||
| - `position:` Object containing the location of interest. _e.g. {latitude: 16.34765, longitude: 12.5432}_ | ||
|
|
||
| returns: `Promise<WeatherProviderData>` | ||
|
|
||
| _Example: Return weather information for location {latitude: 16.34765, longitude: 12.5432}:_ | ||
| ``` | ||
| GET /signalk/v2/api/weather?lat=6.34765&lon=12.5432 | ||
| ``` | ||
| _WeatherProvider method invocation:_ | ||
| ```javascript | ||
| getData({latitude: 16.34765, longitude: 12.5432}); | ||
| ``` | ||
|
|
||
| _Returns:_ | ||
| ```JSON | ||
| { | ||
| "id": "df85kfo", | ||
| "position": {"latitude": 16.34765, "longitude": 12.5432}, | ||
| "observations": [...], | ||
| "forecasts": [...], | ||
| "warnings": [...] | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| **`getObservations(position)`**: This method is called when a request to retrieve observation data for the provided position is made. | ||
|
|
||
|
|
||
| - `position:` Object containing the location of interest. _e.g. {latitude: 16.34765, longitude: 12.5432}_ | ||
|
|
||
|
|
||
| returns: `Promise<WeatherData[]>` | ||
|
|
||
|
|
||
| _Example: Return observations for location {latitude: 16.34765, longitude: 12.5432}:_ | ||
| ``` | ||
| GET /signalk/v2/api/weather/observations?lat=6.34765&lon=12.5432 | ||
| ``` | ||
|
|
||
| _WeatherProvider method invocation:_ | ||
| ```javascript | ||
| getObservations({latitude: 16.34765, longitude: 12.5432}); | ||
| ``` | ||
|
|
||
| _Returns:_ | ||
| ```JSON | ||
| [ | ||
| { | ||
| "date": "2024-05-03T06:00:00.259Z", | ||
| "type": "observation", | ||
| "outside": { ... } | ||
| }, | ||
| { | ||
| "date": "2024-05-03T05:00:00.259Z", | ||
| "type": "observation", | ||
| "outside": { ... } | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| **`getForecasts(position)`**: This method is called when a request to retrieve observation data for the provided position is made. | ||
|
|
||
|
|
||
| - `position:` Object containing the location of interest. _e.g. {latitude: 16.34765, longitude: 12.5432}_ | ||
|
|
||
| returns: `Promise<WeatherData[]>` | ||
|
|
||
|
|
||
| _Example: Return forecasts for location {latitude: 16.34765, longitude: 12.5432}:_ | ||
| ``` | ||
| GET /signalk/v2/api/weather/forecasts?lat=6.34765&lon=12.5432 | ||
| ``` | ||
|
|
||
| _WeatherProvider method invocation:_ | ||
| ```javascript | ||
| getForecasts({latitude: 16.34765, longitude: 12.5432}); | ||
| ``` | ||
|
|
||
| _Returns:_ | ||
| ```JSON | ||
| [ | ||
| { | ||
| "date": "2024-05-03T06:00:00.259Z", | ||
| "type": "point", | ||
| "outside": { ... } | ||
| }, | ||
| { | ||
| "date": "2024-05-03T05:00:00.259Z", | ||
| "type": "point", | ||
| "outside": { ... } | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| **`getWarnings(position)`**: This method is called when a request to retrieve warning data for the provided position is made. | ||
|
|
||
| - `position:` Object containing the location of interest. _e.g. {latitude: 16.34765, longitude: 12.5432}_ | ||
|
|
||
| returns: `Promise<WeatherWarning[]>` | ||
|
|
||
|
|
||
| _Example: Return warnings for location {latitude: 16.34765, longitude: 12.5432}:_ | ||
| ``` | ||
| GET /signalk/v2/api/weather/warnings?lat=6.34765&lon=12.5432 | ||
| ``` | ||
| _WeatherProvider method invocation:_ | ||
| ```javascript | ||
| getWarnings({latitude: 16.34765, longitude: 12.5432}); | ||
| ``` | ||
|
|
||
| _Returns:_ | ||
| ```JSON | ||
| [ | ||
| { | ||
| "startTime": "2024-05-03T05:00:00.259Z", | ||
| "endTime": "2024-05-03T08:00:00.702Z", | ||
| "details": "Strong wind warning.", | ||
| "source": "OpenWeather", | ||
| "type": "Warning" | ||
| } | ||
| ] | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Weather API | ||
|
|
||
| #### (Under Development) | ||
|
|
||
| _Note: This API is currently under development and the information provided here is likely to change._ | ||
|
|
||
| The Signal K server Weather API will provide a common set of operations for interacting with weather sources and (like the Resources API) will rely on a "provider plugin" to facilitate communication with the weather source. | ||
|
|
||
| The Weather API will handle requests to `/signalk/v2/api/weather` paths and pass them to an Weather Provider plugin which will return data fetched from the weather service. | ||
|
|
||
| The following operations are an example of the operations identified for implementation via HTTP `GET` requests: | ||
|
|
||
| ```javascript | ||
| // fetch weather data for the provided location | ||
| GET "/signalk/v2/api/weather?lat=5.432&lon=7.334" | ||
| ``` | ||
|
|
||
| ```javascript | ||
| // Returns an array of observations for the provided location | ||
| GET "/signalk/v2/api/weather/observations?lat=5.432&lon=7.334" | ||
| ``` | ||
|
|
||
| ```javascript | ||
| // Returns an array of forecasts for the provided location | ||
| GET "/signalk/v2/api/weather/forecasts?lat=5.432&lon=7.334" | ||
| ``` | ||
|
|
||
| ```javascript | ||
| // Returnsjavascript an array of warnings for the provided location | ||
| GET "/signalk/v2/api/weather/warnings?lat=5.432&lon=7.334" | ||
| ``` | ||
|
|
||
| The Weather API supports the registration of multiple weather provider plugins. The first plugin registered is set as the default source for all API requests. | ||
|
|
||
| A list of the registered providers can be retrieved using a HTTP `GET` request to `/signalk/v2/api/weather/providers`. | ||
|
|
||
| ```javascript | ||
| GET "/signalk/v2/api/weather/providers" | ||
| ``` | ||
|
|
||
| _Example response:_ | ||
| ```JSON | ||
| { | ||
| "providerId1": { | ||
| "name":"my-provider-1", | ||
| "isDefault":true | ||
| }, | ||
| "providerId2": { | ||
| "name":"my-provider-2", | ||
| "isDefault":false | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The provider can be changed to another of those listed by using a HTTP `POST` request and supplying the provider identifier in the body of the request: | ||
|
|
||
| ```javascript | ||
| POST "/signalk/v2/api/weather/providers" { | ||
| "id": "providerId2" | ||
| } | ||
| ``` |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about the references to autopilot here. Is this just remnants of a copy/paste from another doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy and paste error.