Dataswyft API Platform: Developers Docs
WebsiteGitHubSlackLogin
  • About Dataswyft
    • Community & Support
  • Learn about Dataswyft Platform
    • Decentralized Data Servers
    • Personal Data Account
      • HMIC Permissions
      • Namespaces
      • Single Sign-On
    • Data Wallet
      • Data Wallet Canvas and Solutions
      • CheckD Data Wallet: Release Notes
    • Dataswyft One
      • Compute Tools
  • Build on Dataswyft Platform
    • Dataswyft One APIs
      • Data API
        • Filtering, Querying & Transforming Data
        • Data Debit
      • File Storage API
      • Computations API
      • Postman Collection
    • Integrating with Data Wallets
    • Getting Started
      • Quick Start
      • Developers Portal
        • Updating and Submitting an Application
        • Deleting an Application
        • Application Statuses
      • Application Example - React
        • 1. Environment Setup
        • 2. Create Main Structure
        • 3. Main Page & Routing
        • 4. User Authentication
        • 6. CRUD Operations
        • 5. Component Pages
  • Deploy
    • Application Review
    • Rating Assurance & Certification
    • Live Application Ratings
  • Knowledge Base
    • Security Practices
    • FAQ
    • Glossary of Terms
  • Dataswyft
Powered by GitBook
On this page

Was this helpful?

  1. Build on Dataswyft Platform
  2. Advanced Topics
  3. User Journeys
  4. Password Management
  5. Guides
  6. JavaScript

3. Reading / Writing Data

HAT Data

Response type:

interface HatRecord<T> {
  endpoint: string; // eg. locations
  recordId: string; // A unique record ID of the record.
  data: T; // The Data
}

Write Data

Parameters

Type

namespace

string

endpoint

string

body

object

Response

  • HatRecord\

Example:

const namespace = "testhatapp";
const endpoint = "locations";
const newLocation = {
    latitude: "51.01",
    longitude: "52.12"
};

try {
    const result = await hat.hatData().create(
        namespace, 
        endpoint, 
        newLocation
    );

    if (result.parsedBody) {
        // result.parsedBody contains a HatRecord with the new data.
    }
} catch (error) {
  // Failed to write data...
}

Update Data

Parameters

Type

body

Array>

Response:

  • Array>

Example:

const location = {
    endpoint: "testhatapp/locations",
    recordId: "c14b8f73-157f-40f1-9c77-985d9dea50d2",
    data: {
        latitude: "51.01",
        longitude: "52.12"
    }
};

location.data.latitude = "49.01";

const records = [location]; // Array of records to update. In this case we have only one.

try {
    const result = await hat.hatData().update(records);

    if (result.parsedBody) {
        // result.parsedBody contains an array of HatRecords<T> with the updated location data.
    }
} catch (error) {
  // Failed to update the records...
}

Delete Data

Parameters

Type

recordIds

Array

Response:

  • A successful response message

Example:

const recordIds = ["c14b8f73-157f-40f1-9c77-985d9dea50d2", "d52b8f73-151f-40f1-9c77-932d9dea5daa"];

try {
    const result = await hat.hatData().delete(recordIds);

    if (result.parsedBody) {
        // result.parsedBody contains a successful response message.
        // In this case the result will be {message: "All records deleted"}.
    }
} catch (error) {
  // Failed to delete records...
}

Read Data

The are 2 ways to fetch data:

  1. With default options.

Parameters

Type

namespace

string

endpoint

string

Response

  • Array>

Example:

const namespace = "testhatapp";
const endpoint = "locations";

try{
    const result = await hat.hatData().getAllDefault(namespace, endpoint);

    if (result.parsedBody) {
        // result.parsedBody contains an Array of HatRecord<Location>.
    }
} catch (error) {
    // Failed to fetch the data
}

2. With custom options.

Example:

const options = {
    ordering: "descending",
    orderBy: "lastUpdated"
};
const namespace = "testhatapp";
const endpoint = "locations";

try{
   const result = await hat.hatData().getAll(namespace, endpoint, options);

   if (result.parsedBody) {
       // result.parsedBody contains an Array of HatRecords<Location>, ordered by the last updated date.
   }
} catch (error) {
    // Failed to fetch the data
}

Last updated 3 years ago

Was this helpful?