# Interface ResourcesApi

interface ResourcesApi {
deleteResource(
resType: SignalKResourceType,
resId: string,
providerId?: string,
): Promise<void>;
getResource(
resType: string,
resId: string,
providerId?: string,
): Promise<object>;
listResources(
resType: SignalKResourceType,
params: Record<string, unknown>,
providerId?: string,
): Promise<Record<string, unknown>>;
register(pluginId: string, provider: ResourceProvider): void;
setResource(
resType: SignalKResourceType,
resId: string,
data: Record<string, unknown>,
providerId?: string,
): Promise<void>;
unRegister(pluginId: string): void;
}

- Defined in resourcesapi.ts:27

##### Index

### Methods

deleteResource
getResource
listResources
register
setResource
unRegister

## Methods

### deleteResource

- deleteResource(
  resType: SignalKResourceType,
  resId: string,
  providerId?: string,
  ): Promise<void>

  Delete the resource with the supplied SignalK resource_type and resource_id.

  Note

  Requires a registered Resource Provider. See ResourceProviderRegistry.registerResourceProvider.

  #### Parameters

  - resType: SignalKResourceType

    A SignalKResourceType or user defined resource type.

  - resId: string

    The resource identifier. (e.g. `ac3a3b2d-07e8-4f25-92bc-98e7c92f7f1a`)

  - `Optional` providerId: string

    The id of the Resource Provider plugin to use to complete the request.

  #### Returns Promise<void>

  #### Example

      app.resourcesApi.deleteResource(
        'notes',
        'ac3a3b2d-07e8-4f25-92bc-98e7c92f7f1a'
      ).then ( () => {
        // success
        ...
      }).catch (error) {
        // handle error
        console.log(error.message);
        ...
      }

  - Defined in resourcesapi.ts:162

### getResource

- getResource(
  resType: string,
  resId: string,
  providerId?: string,
  ): Promise<object>

  Retrieve the resource with the supplied SignalK resource_type and resource_id.

  Note

  Requires a registered Resource Provider. See ResourceProviderRegistry.registerResourceProvider.

  #### Parameters

  - resType: string

    A SignalKResourceType or user defined resource type.

  - resId: string

    The resource identifier. (e.g. `ac3a3b2d-07e8-4f25-92bc-98e7c92f7f1a`)

  - `Optional` providerId: string

    The id of the Resource Provider plugin to use to complete the request. Most commonly used for creating a new resource entry when more than one provider is registered for the specified resource type.

  #### Returns Promise<object>

  #### Example

      try {
        const waypoint = await app.resourcesApi.getResource('waypoints', 'ac3a3b2d-07e8-4f25-92bc-98e7c92f7f1a');
        // success
      } catch (error) {
        // handle error
        console.error(error);
        // ...
      }

  - Defined in resourcesapi.ts:87

### listResources

- listResources(
  resType: SignalKResourceType,
  params: Record<string, unknown>,
  providerId?: string,
  ): Promise<Record<string, unknown>>

  Retrieve collection of resource entries of the supplied resource_type matching the provided criteria.

  Note

  Requires a registered Resource Provider. See ResourceProviderRegistry.registerResourceProvider.

  #### Parameters

  - resType: SignalKResourceType

    A SignalKResourceType or user defined resource type.

  - params: Record<string, unknown>

    Object containing `key | value` pairs representing the criteria by which to filter the returned entries.

    Note

    The registered Resource Provider must support the supplied parameters for results to be filtered.

  - `Optional` providerId: string

    The id of the Resource Provider plugin to use to complete the request.

  #### Returns Promise<Record<string, unknown>>

  #### Example

      app.resourcesApi.listResources(
        'waypoints',
        {region: 'fishing_zone'}
      ).then (data => {
        // success
        console.log(data);
        ...
      }).catch (error) {
        // handle error
        console.log(error.message);
        ...
      }

  - Defined in resourcesapi.ts:59

### register

- register(pluginId: string, provider: ResourceProvider): void

  #### Parameters

  - pluginId: string
  - provider: ResourceProvider

  #### Returns void

  - Defined in resourcesapi.ts:28

### setResource

- setResource(
  resType: SignalKResourceType,
  resId: string,
  data: Record<string, unknown>,
  providerId?: string,
  ): Promise<void>

  Create / update value of the resource with the supplied SignalK resource_type and resource_id.

  Note

  Requires a registered Resource Provider. See ResourceProviderRegistry.registerResourceProvider.

  #### Parameters

  - resType: SignalKResourceType

    A SignalKResourceType or user defined resource type.

  - resId: string

    The resource identifier. (e.g. `ac3a3b2d-07e8-4f25-92bc-98e7c92f7f1a`)

  - data: Record<string, unknown>

    A complete and valid resource record.

  - `Optional` providerId: string

    The id of the Resource Provider plugin to use to complete the request. Most commonly used for creating a new resource entry when more than one provider is registered for the specified resource type.

  #### Returns Promise<void>

  #### Example

      app.resourcesApi.setResource(
        'waypoints',
        'ac3a3b2d-07e8-4f25-92bc-98e7c92f7f1a',
        {
          "name": "My Waypoint",
          "feature": {
            "type":"Feature",
            "geometry": {
              "type": "Point",
              "coordinates": [138.5, -38.6]
            },
            "properties":{}
          }
        }
      ).then ( () => {
        // success
        ...
      }).catch (error) {
        // handle error
        console.log(error.message);
        ...
      }

  - Defined in resourcesapi.ts:130

### unRegister

- unRegister(pluginId: string): void

  #### Parameters

  - pluginId: string

  #### Returns void

  - Defined in resourcesapi.ts:29