# 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: { [key: string]: any },
providerId?: string,
): Promise<{ [id: string]: any }>;
register(pluginId: string, provider: ResourceProvider): void;
setResource(
resType: SignalKResourceType,
resId: string,
data: { [key: string]: any },
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:165

### 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:89

### listResources

- listResources(
  resType: SignalKResourceType,
  params: { [key: string]: any },
  providerId?: string,
  ): Promise<{ [id: string]: any }>

  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: { [key: string]: any }

    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<{ [id: string]: any }>

  #### 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: { [key: string]: any },
  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: { [key: string]: any }

    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:132

### unRegister

- unRegister(pluginId: string): void

  #### Parameters

  - pluginId: string

  #### Returns void

  - Defined in resourcesapi.ts:29