GuidesTypeScript API ReferencePython v2 API Reference
Guides

How to get data from an object store layer

This example shows how to read data from and write it to an object store layer on Node.js using HERE Data SDK for TypeScript.

Build and run an app on Node.js

Before you build an app, make sure that you installed all of the dependencies.

To build and run an app on Node.js:

  1. Create an npm project.
mkdir example-app && cd example-app && npm init
  1. Initialize a TypeScript project.
tsc --init
  1. Install node types.
npm install --save-dev @types/node
  1. Install the SDK modules.
npm install --save @here/olp-sdk-authentication @here/olp-sdk-dataservice-read @here/olp-sdk-dataservice-api

Now, everything is set to create the app. 5. Create the index.ts file and app skeleton.

  /**
 * An example of the Node.js app used for reading data from and writing it to an object store layer in the datastore.
 */

class App {
  run() {
    console.log("App works!");
  }
}

const app = new App();
app.run();
  1. Compile and run the app.
tsc && node .

After a successful run, the console displays the following message:

App works!

Create RequestBuilder

You need RequestBuilder to use the ObjectStoreApi functions from @here/olp-sdk-dataservice-api. You can use the ObjectStoreApi functions to request any data from an object store layer.

To create the RequestBuilder instance:

  1. Create the OlpClientSettings object. For instructions, see Create platform client settings.
  2. Create the RequestBuilder instance with RequestFactory that contains the catalog HRN, platform client settings from step 1, API name, and API version.
const requestBuilder = await RequestFactory.create(
 "blob", 
 "v2", 
 settings, 
 HRN.fromString("your-catalog-HRN")
);

Get data from an object store layer

You can request any data from an object store layer using its key or data handle.

To get data from the object store layer:

  1. Create the RequestBuilder object.

  2. Call the getBlobByKey function with the key of the data that you request and layer ID.

const result = await ObjectStoreApi.getBlobByKey(requestBuilder, {
 key: "your-data-key",
 layerId: "your-layer-id"
});

You receive data from the requested key of the selected layer.

Get all keys from an object store layer

You can get a list of all keys from an object store layer.

To get the list of keys:

  1. Create the RequestBuilder object.
  2. Call the listKeys function with the ID of the layer from which you want to get the list of keys.
const result = await ObjectStoreApi.listKeys(requestBuilder, {
   layerId: "your-layer-id"
});

You receive a list of all keys from one level of the selected layer. The list is a virtual directory. Its structure consists of keys in the storage where slashes (/) are used as separators. For each key, the response indicates if it is a folder or object. To retrieve the next level of keys in a folder, call this function recursively with a parent in the query string.

Publish data to an object store layer

For information on how to publish data, see How to publish data to an object store layer.

Delete data from an object store layer

For information on how to publish data, see How to delete data from an object store layer.