# Interface ResourceProviderMethods

interface ResourceProviderMethods {
deleteResource(id: string): Promise<void>;
getResource(id: string, property?: string): Promise<object>;
listResources(
query: { [key: string]: any },
): Promise<{ [id: string]: any }>;
setResource(id: string, value: { [key: string]: any }): Promise<void>;
}

- Defined in resourcesapi.ts:177

##### Index

### Methods

deleteResource
getResource
listResources
setResource

## Methods

### deleteResource

- deleteResource(id: string): Promise<void>

  This method is called when a request is made to remove the specific resource entry with the supplied resource id.

  #### Parameters

  - id: string

    String containing the target resource entry id. e.g. '07894aba-f151-4099-aa4f-5e5773734b99'

    @example: resource request:

        DELETE /signalk/v2/api/resources/routes/07894aba-f151-4099-aa4f-5e5773734b99

    ResourceProvider method invocation:

        deleteResource(
          '07894aba-f151-4099-aa4f-5e5773734b99'
        );

  #### Returns Promise<void>

  - Defined in resourcesapi.ts:382

### getResource

- getResource(id: string, property?: string): Promise<object>

  This method is called when a request is made for a specific resource entry with the supplied `id`. If `property` is supplied then the value of the resource property is returned. If there is no resource associated with the id the call should return Promise.reject.

  #### Parameters

  - id: string

    String containing the target resource entry id. (e.g. '07894aba-f151-4099-aa4f-5e5773734b99')

  - `Optional` property: string

    Name of resource property for which to return the value (in dot notation). e.g. feature.geometry.coordinates

  #### Returns Promise<object>

  #### Example: Resource request:

      GET /signalk/v2/api/resources/routes/07894aba-f151-4099-aa4f-5e5773734b99

  ResourceProvider method invocation:

      getResource(
        '07894aba-f151-4099-aa4f-5e5773734b99'
      );

  Returns:

      {
        "name":"myRoute",
        "description":"A Signal K route",
        "distance":124226.65183615577,
        "feature":{
          "type":"Feature",
          "geometry":{
            "type":"LineString",
            "coordinates":[[-8,-8],[-8.5,-8],[-8.5,-8.4],[-8.7,-8.3]]
          },
          "properties":{}
        },
        "timestamp":"2023-01-01T05:02:54.561Z",
        "$source":"resources-provider"
      }

  #### Example: resource property value request:

      GET /signalk/v2/api/resources/routes/07894aba-f151-4099-aa4f-5e5773734b99/feature/geometry/type

  ResourceProvider method invocation:

      getResource(
        '07894aba-f151-4099-aa4f-5e5773734b99',
        'feature.geometry.type'
      );

  Returns:

      {
        "value": "LineString",
        "timestamp":"2023-01-01T05:02:54.561Z",
        "$source":"resources-provider"
      }

  - Defined in resourcesapi.ts:301

### listResources

- listResources(query: { [key: string]: any }): Promise<{ [id: string]: any }>

  This method is called when a request is made for resource entries that match a specific criteria.

  Note

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

  #### Parameters

  - query: { [key: string]: any }

    Object containing `key | value` pairs representing the parameters by which to filter the returned entries. e.g. {region: 'fishing_zone'}

  #### Returns Promise<{ [id: string]: any }>

  #### Example

  Return waypoints within the bounded area with lower left corner at E5.4 N25.7 & upper right corner E6.9 & N31.2:

      GET /signalk/v2/api/resources/waypoints?bbox=[5.4,25.7,6.9,31.2]

  ResourceProvider method invocation:

      listResources(
        {
          bbox: '5.4,25.7,6.9,31.2'
        }
      );

  Returns:

      {
        "07894aba-f151-4099-aa4f-5e5773734b69": {
          "name":"my Point",
          "description":"A Signal K waypoint",
          "distance":124226.65183615577,
          "feature":{
            "type":"Feature",
            "geometry":{
              "type":"Point",
              "coordinates":[5.7,26.4]
            },
            "properties":{}
          },
          "timestamp":"2023-01-01T05:02:54.561Z",
          "$source":"resources-provider"
        },
        "0c894aba-d151-4099-aa4f-be5773734e99": {
          "name":"another point",
          "description":"Another Signal K waypoint",
          "distance":107226.84,
          "feature":{
            "type":"Feature",
            "geometry":{
              "type":"Point",
              "coordinates":[6.1,29.43]
            },
            "properties":{}
          },
          "timestamp":"2023-01-01T05:02:54.561Z",
          "$source":"resources-provider"
        }
      }

  - Defined in resourcesapi.ts:236

### setResource

- setResource(id: string, value: { [key: string]: any }): Promise<void>

  This method is called when a request is made to save / update a resource entry with the supplied id. The supplied data is a complete resource record.

  #### Parameters

  - id: string

    String containing the id of the resource entry created / updated. e.g. '07894aba-f151-4099-aa4f-5e5773734b99'

  - value: { [key: string]: any }

    Resource data to be stored.

  #### Returns Promise<void>

  #### Example: PUT resource request:

      PUT /signalk/v2/api/resources/routes/07894aba-f151-4099-aa4f-5e5773734b99 {resource_data}

  ResourceProvider method invocation:

      setResource(
        '07894aba-f151-4099-aa4f-5e5773734b99',
        {
          name: 'test route',
          distance': 8000,
          feature: {
            type: 'Feature',
            geometry: {
              type: 'LineString',
              coordinates: [[138.5, -38.6], [138.7, -38.2], [138.9, -38.0]]
            },
            properties:{}
          }
        }
      );

  #### Example: POST resource request:

      POST /signalk/v2/api/resources/routes {resource_data}

  ResourceProvider method invocation:

      setResource(
        '<server_generated_id>',
        {
          name: 'test route',
          distance': 8000,
          feature: {
            type: 'Feature',
            geometry: {
              type: 'LineString',
              coordinates: [[138.5, -38.6], [138.7, -38.2], [138.9, -38.0]]
            },
            properties:{}
          }
        }
      );

  - Defined in resourcesapi.ts:358