Skip to content

Commit

Permalink
Update: Provide the ability to view and set the default provider used…
Browse files Browse the repository at this point in the history
… for resource types. (#1799)

* Add charts to the standard resources list.

* Update openapi definition for charts

* Add configuration store to save default provider settings.

* chore: docs

* Persist default provider settings.

* revert plugin changes

* revert openapi

* Update provider endpoint structure

* Add provider  openapi defintitions

* chore: update docs

* chart identifier is optional

* Add , "mapstyleJSON" definition

* add s-57 chart type

* use config

* update provider paths

* doc: use skServer prefix url path

* simplify code

* debug

---------

Co-authored-by: Teppo Kurki <teppo.kurki@iki.fi>
  • Loading branch information
panaaj and tkurki authored Oct 29, 2024
1 parent d2b5056 commit 2de826f
Show file tree
Hide file tree
Showing 4 changed files with 404 additions and 58 deletions.
56 changes: 45 additions & 11 deletions docs/src/develop/rest-api/resources_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,30 +153,57 @@ _for example:_
HTTP POST 'http://hostname:3000/signalk/v2/api/resources/waypoints'
```

the first provider that was registered for that resource type will be the target of the requested operation (`setResource()`).
By default the first provider that was registered for that resource type will be the target of the requested operation (`setResource()`).

---
You can view the registered providers for a resource type by making the following request:
```typescript
HTTP GET 'http://hostname:3000/signalk/v2/api/resources/{resourceType}/_providers'
```

_Example: `HTTP GET 'http://hostname:3000/signalk/v2/api/resources/charts/_providers'
``` JSON
[
"charts",
"resources-provider"
]
```

You can retrieve the default provider for a resource type by making the following request:

__Specifying the resource provider to be the tartet of the request:__
```typescript
HTTP GET 'http://hostname:3000/signalk/v2/api/resources/{resourceType}/_providers/_default'
```

Example: `HTTP GET 'http://hostname:3000/signalk/v2/api/resources/charts/_providers/_default'
```JSON
"resources-provider"
```

You can change the provider used for writing a resource record in the following ways:
1. Per-request by using the `?provider=` query parameter.
2. Setting a "default" provider for a specific resource type


__1. Per-request by using the `?provider=` query parameter:__

When multiple providers are registered for a resource type the client can specify which provider should be the target of the request by using the query parameter `provider`.

_Example:_
```typescript
HTTP GET 'http://hostname:3000/signalk/v2/api/resources/waypoints?provider=provider-plugin-id'
HTTP GET 'http://hostname:3000/signalk/v2/api/resources/waypoints?provider=my-plugin-id'

HTTP GET 'http://hostname:3000/signalk/v2/api/resources/waypoints/94052456-65fa-48ce-a85d-41b78a9d2111?provider=provider-plugin-id'
HTTP GET 'http://hostname:3000/signalk/v2/api/resources/waypoints/94052456-65fa-48ce-a85d-41b78a9d2111?provider=my-plugin-id'

HTTP PUT 'http://hostname:3000/signalk/v2/api/resources/waypoints/94052456-65fa-48ce-a85d-41b78a9d2111?provider=provider-plugin-id'
HTTP PUT 'http://hostname:3000/signalk/v2/api/resources/waypoints/94052456-65fa-48ce-a85d-41b78a9d2111?provider=my-plugin-id'

HTTP DELETE 'http://hostname:3000/signalk/v2/api/resources/waypoints/94052456-65fa-48ce-a85d-41b78a9d2111?provider=provider-plugin-id'
HTTP DELETE 'http://hostname:3000/signalk/v2/api/resources/waypoints/94052456-65fa-48ce-a85d-41b78a9d2111?provider=my-plugin-id'

HTTP POST 'http://hostname:3000/signalk/v2/api/resources/waypoints?provider=provider-plugin-id'
HTTP POST 'http://hostname:3000/signalk/v2/api/resources/waypoints?provider=my-plugin-id'
```

the value assigned to `provider` is the `plugin id` of the resource provider plugin.

The plugin id can be obtained from the Signal K server url `http://hostname:3000/plugins`.
The plugin id can be obtained from the Signal K server url _http://hostname:3000/skServer/plugins_.

_Example:_

Expand All @@ -187,13 +214,20 @@ HTTP GET 'http://hostname:3000/plugins'
```JSON
[
{
"id": "sk-resources-fs", // <-- plugin id
"id": "mysk-resource-plugin", // <-- plugin id
"name": "Resources Provider",
"packageName": "sk-resources-fs",
"packageName": "mysk-resource-plugin",
"version": "1.3.0",
...
},
...
]
```
__2. Setting a default provider for a resource type:__

To change the default provider for a resource type make a POST request to *http://hostname:3000/signalk/v2/api/resources/{resourceType}/_providers/_default/{pluginId}* where `pluginId` is the id of resource provider plugin.

_Example: Direct create new chart source entries to `my-chart-plugin`._
```typescript
HTTP POST 'http://hostname:3000/signalk/v2/api/resources/charts/_providers/_default/my-chart-plugin'
```
2 changes: 1 addition & 1 deletion src/api/course/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class CourseApi {
}
try {
const result = await this.activateRoute(req.body)
console.log(this.courseInfo)
debug(this.courseInfo)
if (result) {
this.emitCourseInfo()
res.status(200).json(Responses.ok)
Expand Down
Loading

0 comments on commit 2de826f

Please sign in to comment.