Data Management - helixml/apps-client

The @helixml/apps-client library is a TypeScript-based tool for interacting with data stored in Helix Cloud. It utilizes Axios for making HTTP requests, and offers methods for retrieving, updating, and manipulating data.

Retrieving Data

To retrieve data from Helix Cloud, you can use the get method provided by @helixml/apps-client. Here’s an example:

import { Client } from '@helixml/apps-client';

const client = new Client('https://your-helix-cloud-instance.com');

client.get('/data/your-data-endpoint')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});

This code creates a new instance of the Client class, then makes a GET request to the specified endpoint. The response data is then logged to the console.

Updating Data

To update data in Helix Cloud, you can use the put method provided by @helixml/apps-client. Here’s an example:

import { Client } from '@helixml/apps-client';

const client = new Client('https://your-helix-cloud-instance.com');

const updatedData = {
field1: 'new value',
field2: 42,
};

client.put('/data/your-data-endpoint', updatedData)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});

This code creates a new instance of the Client class, then makes a PUT request to the specified endpoint with the updated data. The response data is then logged to the console.

Manipulating Data

@helixml/apps-client also provides methods for deleting data (delete) and creating new data (post). Here’s an example of using delete:

import { Client } from '@helixml/apps-client';

const client = new Client('https://your-helix-cloud-instance.com');

client.delete('/data/your-data-endpoint/123')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});

This code makes a DELETE request to the specified endpoint and ID, removing the corresponding data.

For creating new data, you can use the post method:

import { Client } from '@helixml/apps-client';

const client = new Client('https://your-helix-cloud-instance.com');

const newData = {
field1: 'new value',
field2: 42,
};

client.post('/data/your-data-endpoint', newData)
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error);
});

This code makes a POST request to the specified endpoint with the new data, creating a new record.

Sources: