Skip to content
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

[supersceded by #1381] Implement Course and Resources API #1361

Closed
wants to merge 418 commits into from
Closed
Show file tree
Hide file tree
Changes from 184 commits
Commits
Show all changes
418 commits
Select commit Hold shift + click to select a range
43bb1aa
align openApi.json
panaaj Jan 1, 2022
e66fcac
move `store.ts` to serverstate` folder
panaaj Jan 2, 2022
12c54df
change saved couorse path to serverstate
panaaj Jan 3, 2022
0559e65
regresstion testing fixes
panaaj Jan 8, 2022
7e4ffa2
add activeRouote/reverse path
panaaj Jan 8, 2022
909ab03
chore: update OpenApi responses
panaaj Jan 9, 2022
fe575bb
regression testing fixes 2
panaaj Jan 9, 2022
0f437e5
style: linter fix
tkurki Jan 9, 2022
efb523e
style: no-inferrable-types
tkurki Jan 9, 2022
572c0a2
fix: double definition of CourseApplication
tkurki Jan 9, 2022
ba955b1
chore: use global Position type
tkurki Jan 9, 2022
656bdc0
refactor: prefer object spread over Object.assign
tkurki Jan 9, 2022
91a7abb
fix: SecurityStrategy.shouldAllowPut must have Request
tkurki Jan 9, 2022
a3c376d
fix: updateAllowed(request) is required
tkurki Jan 9, 2022
afebb58
chore: this.server is initialised in constructor
tkurki Jan 9, 2022
ea24705
refactor: use Destination type
tkurki Jan 9, 2022
3f2a709
review updates 1
panaaj Jan 10, 2022
870b131
removed periodic delta transmission
panaaj Jan 10, 2022
32bea63
update types
panaaj Jan 12, 2022
c84fdfb
chore: version 1.41.0-beta.1
tkurki Jan 14, 2022
5071126
chore: convert ports to ts
tkurki Jan 14, 2022
8ad9c16
chore: convert deltachain & deltastats to ts
tkurki Jan 14, 2022
27875a9
chore: convert security.js to ts
tkurki Jan 15, 2022
3852d9a
1.41.0-beta.2
tkurki Jan 15, 2022
f9bb471
chore: use npm run watch, not dev
tkurki Jan 15, 2022
605cc90
fix: event emitting on app
tkurki Jan 15, 2022
eb874e3
1.41.0-beta.3
tkurki Jan 15, 2022
694a264
chore: drop aws-sdk from streams' dependencies
tkurki Jan 16, 2022
205625f
chore: @signalk/[email protected]
tkurki Jan 16, 2022
293557f
chore: debug ^4.3.3
tkurki Jan 16, 2022
4e207a5
add test for ApiRequst path
panaaj Jan 18, 2022
c71cfdf
fix: debug output of event payload
tkurki Jan 20, 2022
b1e351d
chore: update docs
panaaj Jan 21, 2022
c93e0bc
POST, PUT & DELETE response.message = resource id
panaaj Jan 21, 2022
7acf3de
feature: use debug wrapper
tkurki Jan 22, 2022
55fe8aa
feature: use debug wrapper in pipedprovider & streams
tkurki Jan 22, 2022
4def354
Merge pull request #1375 from SignalK/debug-wrapper
tkurki Jan 23, 2022
0af55d1
chore: @signalk/[email protected]
tkurki Jan 23, 2022
8866f3d
1.41.0-beta.4
tkurki Jan 23, 2022
9aa5e55
chore: remove aws-sdk dependency
tkurki Jan 23, 2022
9fa5d5e
chore: add prettier to @signalk/streams
tkurki Jan 23, 2022
f800fc9
style: format @signalk/streams
tkurki Jan 23, 2022
038b09d
chore: use npm workspace
tkurki Jan 23, 2022
ee52722
fix: add nmea0183 and n2k explicitly
tkurki Jan 23, 2022
684c1bc
fix: use ~ instead of node_modules
tkurki Jan 23, 2022
bff5eeb
chore: add CI builds for packages
tkurki Jan 23, 2022
d84e90b
style: ci to check formatting in streams and admin ui
tkurki Jan 23, 2022
559dc91
Merge pull request #1376 from SignalK/improve-packages-builds
tkurki Jan 24, 2022
cfcad1d
chore: @signalk/[email protected]
tkurki Jan 24, 2022
157958a
1.41.0
tkurki Jan 24, 2022
7aeb9c2
chore: add build-docker branch to debug docker builds
tkurki Jan 24, 2022
9912200
fix: docker build (#1377)
tkurki Jan 25, 2022
bcc80ca
fix: nmea0183-signalk logging (#1378)
tkurki Jan 25, 2022
c2c3e70
doc: update RPi instructions for Node.js 16 / 1.41 (#1379)
MatsA Jan 26, 2022
3cd86a4
fix type definitions
panaaj Jan 27, 2022
f9f5c14
update debug use
panaaj Jan 27, 2022
ee0d8ce
Add Signal K standard resource path handling
panaaj Nov 7, 2021
9dd084b
add OpenApi definition file
panaaj Nov 7, 2021
20970e0
chore: fix lint errors
panaaj Nov 7, 2021
a74cc7f
addressed comments re parameters
panaaj Nov 9, 2021
dafecf6
add API definitions
panaaj Nov 9, 2021
96b925d
add geohash library
panaaj Nov 9, 2021
755f22f
add API endpoint processing
panaaj Nov 9, 2021
eaafd7b
align with openapi definitions
panaaj Nov 9, 2021
3b1d228
Added Resource_Provider documentation
panaaj Nov 11, 2021
25430a4
Add register / unregister
panaaj Nov 14, 2021
6f3cd49
add constructor
panaaj Nov 14, 2021
d05dd7d
add getResource function
panaaj Nov 14, 2021
f35ca63
chore: fix formatting
panaaj Nov 15, 2021
3cdf6e5
OpenApi descriptions
panaaj Nov 15, 2021
55cc8b7
add pluginId to register() function
panaaj Nov 20, 2021
f926ad5
add pluginId to unRegister function
panaaj Nov 20, 2021
07059c5
set plugin id as delta source
panaaj Nov 20, 2021
e006b4f
unregister only requires plugin id
panaaj Nov 20, 2021
2867ca7
update docs
panaaj Nov 20, 2021
cb9d5f9
add resource attribute req to query object
panaaj Nov 21, 2021
dfd8be1
chore: update docs with query object examples.
panaaj Nov 21, 2021
bdf213d
chore: linted
panaaj Nov 21, 2021
fd4a38a
chore: return value descriptions to show a Promise
panaaj Nov 21, 2021
75ea43a
specify SignalKResourceType
panaaj Nov 21, 2021
efebc39
move interfaces to server-api
panaaj Nov 21, 2021
07735a7
cleanup express route handling
panaaj Nov 21, 2021
3bb78a0
add ResourceProvider types to server-api
panaaj Nov 22, 2021
bf6da86
refactor: use Express types
tkurki Nov 21, 2021
130f94a
fix type
panaaj Nov 22, 2021
7bf17a0
chore: lint
panaaj Nov 22, 2021
8ffa646
chore: update return type
panaaj Nov 22, 2021
e039a92
Use Express routing params for processing requests
panaaj Nov 22, 2021
f892617
throw on error
panaaj Nov 23, 2021
273fc65
PUT/POST payloads directly in `body`..not `value:`
panaaj Nov 23, 2021
2464cf3
remove resourceId validity check on GET
panaaj Nov 24, 2021
f94625c
chore: Updated documentation
panaaj Nov 24, 2021
25b3145
add chartId test & require alignment with spec.
panaaj Nov 24, 2021
5f92793
add charts API methods
panaaj Nov 24, 2021
05a3160
allow registering custom resource types
panaaj Nov 25, 2021
66db035
chore: update docs
panaaj Nov 25, 2021
e7f3ee2
chore: lint
panaaj Nov 25, 2021
19ef696
update types
panaaj Nov 27, 2021
087620d
align response formatting forGET ./resources/
panaaj Nov 27, 2021
27ec94e
Add Signal K standard resource path handling
panaaj Nov 7, 2021
1d28082
add OpenApi definition file
panaaj Nov 7, 2021
c2b3bbf
chore: fix lint errors
panaaj Nov 7, 2021
9dbd1c0
addressed comments re parameters
panaaj Nov 9, 2021
f9aabb7
add API definitions
panaaj Nov 9, 2021
b1478cf
add API endpoint processing
panaaj Nov 9, 2021
16ebf2e
align with openapi definitions
panaaj Nov 9, 2021
44b7ba1
Added Resource_Provider documentation
panaaj Nov 11, 2021
e53b734
Add register / unregister
panaaj Nov 14, 2021
41e2616
add constructor
panaaj Nov 14, 2021
5a3acb8
add getResource function
panaaj Nov 14, 2021
694f8fa
chore: fix formatting
panaaj Nov 15, 2021
523fd50
OpenApi descriptions
panaaj Nov 15, 2021
6bbaf2d
add pluginId to register() function
panaaj Nov 20, 2021
99bdce7
add pluginId to unRegister function
panaaj Nov 20, 2021
0bae09f
set plugin id as delta source
panaaj Nov 20, 2021
3c33925
unregister only requires plugin id
panaaj Nov 20, 2021
9969eb1
update docs
panaaj Nov 20, 2021
eb835d2
add resource attribute req to query object
panaaj Nov 21, 2021
774560e
chore: update docs with query object examples.
panaaj Nov 21, 2021
984a200
chore: linted
panaaj Nov 21, 2021
da9693f
chore: return value descriptions to show a Promise
panaaj Nov 21, 2021
8b43064
specify SignalKResourceType
panaaj Nov 21, 2021
94ee906
move interfaces to server-api
panaaj Nov 21, 2021
16e2e68
cleanup express route handling
panaaj Nov 21, 2021
142f2bc
add ResourceProvider types to server-api
panaaj Nov 22, 2021
55ae9e3
refactor: use Express types
tkurki Nov 21, 2021
273cbc4
fix type
panaaj Nov 22, 2021
a359bf4
chore: lint
panaaj Nov 22, 2021
7a7e406
chore: update return type
panaaj Nov 22, 2021
fbadba5
Use Express routing params for processing requests
panaaj Nov 22, 2021
fb6b12c
throw on error
panaaj Nov 23, 2021
7e71f86
PUT/POST payloads directly in `body`..not `value:`
panaaj Nov 23, 2021
18503d4
remove resourceId validity check on GET
panaaj Nov 24, 2021
f18a8e1
chore: Updated documentation
panaaj Nov 24, 2021
5b7b998
add chartId test & require alignment with spec.
panaaj Nov 24, 2021
2b04dfe
add charts API methods
panaaj Nov 24, 2021
aaf76fa
allow registering custom resource types
panaaj Nov 25, 2021
3d7d6f0
chore: update docs
panaaj Nov 25, 2021
3844b06
chore: lint
panaaj Nov 25, 2021
4ca91f3
update types
panaaj Nov 27, 2021
b376130
align response formatting forGET ./resources/
panaaj Nov 27, 2021
3ef8c73
add resourceApi to index.ts after rebase
panaaj Nov 30, 2021
f768c7f
add charts API methods
panaaj Dec 3, 2021
c00fd8d
add securityStrategy test
panaaj Dec 5, 2021
3eaeccd
chore: update docs
panaaj Dec 5, 2021
ccb6dff
chore: update docs
panaaj Dec 6, 2021
b7e7c4d
fix chart identifier
panaaj Dec 6, 2021
1df55d9
chore: fix lint errors
panaaj Dec 7, 2021
11deafb
refactor: tweak types
tkurki Dec 12, 2021
eb77914
move provider.methods check to `register()`
panaaj Dec 12, 2021
5d13000
Use POST for paths that DO NOT specify an id
panaaj Dec 18, 2021
46dfa0c
fix api request id validation
panaaj Dec 20, 2021
6081501
init courseApi
panaaj Dec 4, 2021
e195d26
update detlas
panaaj Dec 4, 2021
f0f1dfb
init courseApi
panaaj Dec 4, 2021
f51cfb6
update detlas
panaaj Dec 4, 2021
f3ff1f6
enable put processing
panaaj Dec 5, 2021
5557653
chore: lint
panaaj Dec 6, 2021
d8c5685
add 30sec delta interval
panaaj Dec 7, 2021
454ae4a
chore: lint
panaaj Dec 12, 2021
a38fb8b
init courseApi
panaaj Dec 4, 2021
1572e86
update detlas
panaaj Dec 4, 2021
3024f23
init courseApi
panaaj Dec 4, 2021
c4296c9
update detlas
panaaj Dec 4, 2021
4f2f3ae
enable put processing
panaaj Dec 5, 2021
fb803ca
chore: lint
panaaj Dec 6, 2021
d84348e
add 30sec delta interval
panaaj Dec 7, 2021
74336c4
chore: lint
panaaj Dec 12, 2021
d015ba9
init courseApi
panaaj Dec 4, 2021
c102583
update detlas
panaaj Dec 4, 2021
9c6a348
init courseApi
panaaj Dec 4, 2021
7f077d6
update detlas
panaaj Dec 4, 2021
a3ed8b1
enable put processing
panaaj Dec 5, 2021
d8a6aae
chore: lint
panaaj Dec 6, 2021
1efd58b
add 30sec delta interval
panaaj Dec 7, 2021
39d961a
chore: lint
panaaj Dec 12, 2021
800770f
init courseApi
panaaj Dec 4, 2021
3ca5a89
update detlas
panaaj Dec 4, 2021
bfed30d
init courseApi
panaaj Dec 4, 2021
86a5bc3
update detlas
panaaj Dec 4, 2021
020374a
enable put processing
panaaj Dec 5, 2021
e9dee2e
chore: lint
panaaj Dec 6, 2021
b61624c
add 30sec delta interval
panaaj Dec 7, 2021
ea5de64
chore: lint
panaaj Dec 12, 2021
c7672a0
init courseApi
panaaj Dec 4, 2021
f8dcc1d
update detlas
panaaj Dec 4, 2021
9538cc6
init courseApi
panaaj Dec 4, 2021
98aa838
update detlas
panaaj Dec 4, 2021
5d38536
enable put processing
panaaj Dec 5, 2021
a204cee
chore: lint
panaaj Dec 6, 2021
f0877a6
add 30sec delta interval
panaaj Dec 7, 2021
33e5e91
chore: lint
panaaj Dec 12, 2021
2ec2dda
init courseApi
panaaj Dec 4, 2021
643ed78
update detlas
panaaj Dec 4, 2021
0b94dfc
init courseApi
panaaj Dec 4, 2021
2bf52aa
update detlas
panaaj Dec 4, 2021
8a39c44
enable put processing
panaaj Dec 5, 2021
f82b700
chore: lint
panaaj Dec 6, 2021
719671f
add 30sec delta interval
panaaj Dec 7, 2021
2f8bb59
chore: lint
panaaj Dec 12, 2021
5cb4663
init courseApi
panaaj Dec 4, 2021
4ac7b0b
update detlas
panaaj Dec 4, 2021
4dbfc86
init courseApi
panaaj Dec 4, 2021
e7740fe
update detlas
panaaj Dec 4, 2021
549595e
enable put processing
panaaj Dec 5, 2021
57d47bb
chore: lint
panaaj Dec 6, 2021
44d29c8
add 30sec delta interval
panaaj Dec 7, 2021
3aa6a25
chore: lint
panaaj Dec 12, 2021
7b461ea
init courseApi
panaaj Dec 4, 2021
dc841e1
update detlas
panaaj Dec 4, 2021
511c7d5
init courseApi
panaaj Dec 4, 2021
4e264d4
update detlas
panaaj Dec 4, 2021
1e54d3a
enable put processing
panaaj Dec 5, 2021
88166ed
chore: lint
panaaj Dec 6, 2021
f10f7f3
add 30sec delta interval
panaaj Dec 7, 2021
75683ca
chore: lint
panaaj Dec 12, 2021
f5f255d
persist courseInfo to settings file
panaaj Dec 31, 2021
5b21c33
add getVesselPosition
panaaj Jan 1, 2022
55806bc
align openApi.json
panaaj Jan 1, 2022
0127a53
move `store.ts` to serverstate` folder
panaaj Jan 2, 2022
2ba8a68
change saved couorse path to serverstate
panaaj Jan 3, 2022
f0920d6
regresstion testing fixes
panaaj Jan 8, 2022
cabf92b
add activeRouote/reverse path
panaaj Jan 8, 2022
76efbb0
chore: update OpenApi responses
panaaj Jan 9, 2022
37a4966
regression testing fixes 2
panaaj Jan 9, 2022
90addc7
style: linter fix
tkurki Jan 9, 2022
652f093
style: no-inferrable-types
tkurki Jan 9, 2022
49c27ec
fix: double definition of CourseApplication
tkurki Jan 9, 2022
3cf2c61
chore: use global Position type
tkurki Jan 9, 2022
97785a4
refactor: prefer object spread over Object.assign
tkurki Jan 9, 2022
269c896
fix: SecurityStrategy.shouldAllowPut must have Request
tkurki Jan 9, 2022
348e331
fix: updateAllowed(request) is required
tkurki Jan 9, 2022
9b1e0a8
chore: this.server is initialised in constructor
tkurki Jan 9, 2022
c29b355
refactor: use Destination type
tkurki Jan 9, 2022
23322dd
review updates 1
panaaj Jan 10, 2022
1dd4426
removed periodic delta transmission
panaaj Jan 10, 2022
be7dfb4
update types
panaaj Jan 12, 2022
f0f3648
add test for ApiRequst path
panaaj Jan 18, 2022
eab4c55
chore: update docs
panaaj Jan 21, 2022
5afc8b7
POST, PUT & DELETE response.message = resource id
panaaj Jan 21, 2022
16212a7
fix type definitions
panaaj Jan 27, 2022
685cffc
update debug use
panaaj Jan 27, 2022
e1838b6
update after v1.41 rebase
panaaj Jan 27, 2022
1576d55
fix debug post v1.41
panaaj Jan 27, 2022
709ec3e
add shouldAllowPut() to Security Strategy
panaaj Jan 27, 2022
230e68f
fix SecurityStrategy import path
panaaj Jan 27, 2022
aca6dfb
add any return type to app.emit to allow compilation
panaaj Jan 27, 2022
9825c0c
Merge branch 'course-api' of https://github.com/SignalK/signalk-serve…
panaaj Jan 27, 2022
d851a9f
chore: lint streams
panaaj Jan 27, 2022
f447545
chore: lint courseApi
panaaj Jan 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
338 changes: 338 additions & 0 deletions RESOURCE_PROVIDER_PLUGINS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,338 @@
# Resource Provider plugins

_This document should be read in conjunction with [SERVERPLUGINS.md](./SERVERPLUGINS.md) as it contains additional information regarding the development of plugins that facilitate the storage and retrieval of resource data._

---

## Overview

The SignalK specification defines the path `/signalk/v1/api/resources` for accessing resources to aid in navigation and operation of the vessel.

It also defines the schema for the following __Common__ resource types:
- routes
- waypoints
- notes
- regions
- charts

each with its own path under the root `resources` path _(e.g. `/signalk/v1/api/resources/routes`)_.

It should also be noted that the `/signalk/v1/api/resources` path can also host other types of resource data which can be grouped within a __Custom__ path name _(e.g. `/signalk/v1/api/resources/fishingZones`)_.

The SignalK server does not natively provide the ability to store or retrieve resource data for either __Common__ and __Custom__ resource types.
This functionality needs to be provided by one or more server plugins that handle the data for specific resource types.

These plugins are called __Resource Providers__.

This de-coupling of resource request handling and storage / retrieval provides great flexibility to ensure that an appropriate resource storage solution can be configured for your SignalK implementation.

SignalK server handles requests for both __Common__ and __Custom__ resource types in a similar manner, the only difference being that it does not perform any validation on __Custom__ resource data, so a plugin can act a s a provider for both types.

---
## Server Operation:

The Signal K server handles all requests to `/signalk/v1/api/resources` and all sub-paths, before passing on the request to the registered resource provider plugin.

The following operations are performed by the server when a request is received:
- Checks for a registered provider for the resource type
- Checks that ResourceProvider methods are defined
- For __Common__ resource types, checks the validity of the:
- Resource id
- Submitted resource data.

Upon successful completion of these operations the request will then be passed to the registered resource provider plugin.

---
## Resource Provider plugin:

For a plugin to be considered a Resource Provider it needs to implement the `ResourceProvider` interface.

By implementing this interface the plugin is able to register with the SignalK server the:
- Resource types provided for by the plugin
- Methods to used to action requests.

It is these methods that perform the retrival, saving and deletion of resources from storage.


### Resource Provider Interface

---
The `ResourceProvider` interface defines the contract between the the Resource Provider plugin and the SignalK server and has the following definition _(which it and other related types can be imported from `@signalk/server-api`)_:

```typescript
interface ResourceProvider: {
types: string[],
methods: {
listResources: (type:string, query: {[key:string]:any})=> Promise<any>
getResource: (type:string, id:string)=> Promise<any>
setResource: (type:string, id:string, value:{[key:string]:any})=> Promise<any>
deleteResource: (type:string, id:string)=> Promise<any>
}
}
```
where:

- `types`: An array containing a list of resource types provided for by the plugin. These can be a mixture of both __Common__ and __Custom__ resource types.
- `methods`: An object containing the methods resource requests are passed to by the SignalK server. The plugin __MUST__ implement each method, even if that operation is not supported by the plugin!

#### __Method Details:__

---
__`listResources(type, query)`__: This method is called when a request is made for resource entries of a specific resource type that match a specifiec criteria.

_Note: It is the responsibility of the resource provider plugin to filter the resources returned as per the supplied query parameters._

`type:` String containing the type of resource to retrieve.

`query:` Object contining `key | value` pairs repesenting the parameters by which to filter the returned entries. _e.g. {distance,'50000}_

`returns:`
- Resolved Promise containing a list of resource entries on completion.
- Rejected Promise containing an Error if incomplete or not implemented.


_Example resource request:_
```
GET /signalk/v1/api/resources/waypoints?bbox=5.4,25.7,6.9,31.2&distance=30000
```
_ResourceProvider method invocation:_

```javascript
listResources(
'waypoints',
{
bbox: '5.4,25.7,6.9,31.2',
distance: 30000
}
);
```

---
__`getResource(type, id)`__: This method is called when a request is made for a specific resource entry of the supplied resource type and id.

`type:` String containing the type of resource to retrieve.

`id:` String containing the target resource entry id. _e.g. 'urn:mrn:signalk:uuid:07894aba-f151-4099-aa4f-5e5773734b99'_

`returns:`
- Resolved Promise containing the resource entry on completion.
- Rejected Promise containing an Error if incomplete or not implemented.

_Example resource request:_
```
GET /signalk/v1/api/resources/routes/urn:mrn:signalk:uuid:07894aba-f151-4099-aa4f-5e5773734b99
```
_ResourceProvider method invocation:_

```javascript
getResource(
'routes',
'urn:mrn:signalk:uuid:07894aba-f151-4099-aa4f-5e5773734b99'
);
```

---
__`setResource(type, id, value)`__: This method is called when a request is made to save / update a resource entry of the specified resource type, with the supplied id and data.

`type:` String containing the type of resource to store.

`id:` String containing the target resource entry id. _e.g. 'urn:mrn:signalk:uuid:07894aba-f151-4099-aa4f-5e5773734b99'_

`value:` Resource data to be stored.

`returns:`
- Resolved Promise containing a list of resource entries on completion.
- Rejected Promise containing an Error if incomplete or not implemented.

_Example PUT resource request:_
```
PUT /signalk/v1/api/resources/routes/urn:mrn:signalk:uuid:07894aba-f151-4099-aa4f-5e5773734b99 {resource_data}
```
_ResourceProvider method invocation:_

```javascript
setResource(
'routes',
'urn:mrn:signalk:uuid:07894aba-f151-4099-aa4f-5e5773734b99',
{<resource_data>}
);
```

_Example POST resource request:_
```
POST /signalk/v1/api/resources/routes {resource_data}
```
_ResourceProvider method invocation:_

```javascript
setResource(
'routes',
'<server_generated_id>',
{<resource_data>}
);
```

---
__`deleteResource(type, id)`__: This method is called when a request is made to remove the specific resource entry of the supplied resource type and id.

`type:` String containing the type of resource to delete.

`id:` String containing the target resource entry id. _e.g. 'urn:mrn:signalk:uuid:07894aba-f151-4099-aa4f-5e5773734b99'_

`returns:`
- Resolved Promise on completion.
- Rejected Promise containing an Error if incomplete or not implemented.

_Example resource request:_
```
DELETE /signalk/v1/api/resources/routes/urn:mrn:signalk:uuid:07894aba-f151-4099-aa4f-5e5773734b99
```
_ResourceProvider method invocation:_

```javascript
deleteResource(
'routes',
'urn:mrn:signalk:uuid:07894aba-f151-4099-aa4f-5e5773734b99'
);
```

### Registering a Resource Provider:
---

To register the resource provider plugin with the SignalK server, the server's `resourcesApi.register()` function should be called during plugin startup.

The server `resourcesApi.register()` function has the following signature:

```typescript
app.resourcesApi.register(pluginId: string, resourceProvider: ResourceProvider)
```
where:
- `pluginId`: is the plugin's id
- `resourceProvider`: is a reference to the plugins ResourceProvider interface.

_Note: A resource type can only have one registered plugin, so if more than one plugin attempts to register as a provider for the same resource type, the first plugin to call the `register()` function will be registered by the server for the resource types defined in the ResourceProvider interface!_

_Example:_
```javascript
module.exports = function (app) {

let plugin= {
id: 'mypluginid',
name: 'My Resource Providerplugin',
resourceProvider: {
types: ['routes','waypoints'],
methods: {
listResources: (type, params)=> { ... },
getResource: (type:string, id:string)=> { ... } ,
setResource: (type:string, id:string, value:any)=> { ... },
deleteResource: (type:string, id:string)=> { ... }
}
}
}

plugin.start = function(options) {
...
app.resourcesApi.register(plugin.id, plugin.resourceProvider);
}
}
```

### Un-registering the Resource Provider:
---

When a resource provider plugin is disabled, it should un-register itself to ensure resource requests are no longer directed to it by calling the SignalK server. This should be done by calling the server's `resourcesApi.unRegister()` function during shutdown.

The server `resourcesApi.unRegister()` function has the following signature:

```typescript
app.resourcesApi.unRegister(pluginId: string)
```
where:
- `pluginId`: is the plugin's id


_Example:_
```javascript
module.exports = function (app) {

let plugin= {
id: 'mypluginid',
name: 'My Resource Providerplugin',
resourceProvider: {
types: [ ... ],
methods: { ... }
}
}

plugin.stop = function(options) {
app.resourcesApi.unRegister(plugin.id);
...
}
}
```

---

### __Example:__

Resource Provider plugin providing for the retrieval of routes & waypoints.

```javascript
// SignalK server plugin
module.exports = function (app) {

let plugin= {
id: 'mypluginid',
name: 'My Resource Providerplugin',
// ResourceProvider interface
resourceProvider: {
types: ['routes','waypoints'],
methods: {
listResources: (type, params)=> {
return new Promise( (resolve, reject) => {
// fetch resource entries from storage
....
if(ok) { // success
resolve({
'id1': { ... },
'id2': { ... },
});
} else { // error
reject(new Error('Error encountered!')
}
}
},
getResource: (type, id)=> {
// fetch resource entries from storage
....
if(ok) { // success
return Promise.resolve({
...
});
} else { // error
reject(new Error('Error encountered!')
}
},
setResource: (type, id, value)=> {
// not implemented
return Promise.reject(new Error('NOT IMPLEMENTED!'));
},
deleteResource: (type, id)=> {
// not implemented
return Promise.reject(new Error('NOT IMPLEMENTED!'));
}
}
},

start: (options)=> {
...
app.resourceApi.register(this.id, this.resourceProvider);
},

stop: ()=> {
app.resourceApi.unRegister(this.id);
...
}
}
}
```
Loading