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

Update: Provide the ability to view and set the default provider used for resource types. #1799

Merged
merged 19 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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