interfaceHatRecord<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:
constnamespace="testhatapp";constendpoint="locations";constnewLocation= { latitude:"51.01", longitude:"52.12"};try {constresult=awaithat.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:
constlocation= { endpoint:"testhatapp/locations", recordId:"c14b8f73-157f-40f1-9c77-985d9dea50d2", data: { latitude:"51.01", longitude:"52.12" }};location.data.latitude ="49.01";constrecords= [location]; // Array of records to update. In this case we have only one.try {constresult=awaithat.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:
constrecordIds= ["c14b8f73-157f-40f1-9c77-985d9dea50d2","d52b8f73-151f-40f1-9c77-932d9dea5daa"];try {constresult=awaithat.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:
With default options.
Parameters
Type
namespace
string
endpoint
string
Response
Array>
Example:
constnamespace="testhatapp";constendpoint="locations";try{constresult=awaithat.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:
constoptions= { ordering:"descending", orderBy:"lastUpdated"};constnamespace="testhatapp";constendpoint="locations";try{constresult=awaithat.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}