Skip to content

Latest commit

 

History

History
336 lines (233 loc) · 9.19 KB

README.md

File metadata and controls

336 lines (233 loc) · 9.19 KB

NodeJS

Installation

The NodeJS client library for Crudly is maintained as an NPM package. You can find the NPM package page here: https://www.npmjs.com/package/@crudly/crudly

You can install it by running:

npm install @crudly/crudly

Setup

To begin working with Crudly you will need to initialise a Crudly object like so:

import { createCrudly } from "@crudly/crudly";

const crudly = createCrudly({
  projectId: "<PROJECT ID>",
  projectKey: "<PROJECT KEY>",
});

Usage

The Crudly object exposes a number of methods for interacting with your project's data. These methods are documented below.

Entity

createEntity(tableName, entity)

Description

Create an entity

Parameters

Name Type Description Optional
tableName TableName (string) The name of the table
entity Entity (object) The entity to create

Return Value

Type Description
EntityId (string) ID of the created entity

Errors

Type Description
CrudlyValidationError The provided entity did not fit the table schema
CrudlyNotFoundError The table was not found
CrudlyRateLimitExceededError Rate limit exceeded

Example

const entityId = await crudly.createEntity("users", {
  firstName: "alex",
  lastName: "smith",
  email: "alex.smith@gmail.com",
});
createEntities(tableName, entities)

Description

Create multiple entities

Parameters

Name Type Description Optional
tableName TableName (string) The name of the table
entities Entity[] (object[]) The entities to create

Return Value

Type Description
void

Errors

Type Description
CrudlyValidationError One ore more provided entities did not fit the table schema
CrudlyNotFoundError The table was not found
CrudlyRateLimitExceededError Rate limit exceeded

Example

await crudly.createEntities("users", [
  {
    firstName: "alex",
    lastName: "smith",
    email: "alex.smith@gmail.com",
  },
  {
    firstName: "jane",
    lastName: "bloggs",
    email: "jane.bloggs@hotmail.com",
  },
]);
putEntity(tableName, id, entity)

Description

Create an entity with specified ID.

Parameters

Name Type Description Optional
tableName TableName (string) The name of the table
id EntityId (string) The ID of the entity to create
entity Entity (object) The entity to create

Return Value

Type Description
EntityId (string) The ID of the created entity

Errors

Type Description
CrudlyValidationError The provided entity did not fit the table schema
CrudlyNotFoundError The table was not found
CrudlyRateLimitExceededError Rate limit exceeded

Example

const entityId = await crudly.putEntity(
  "users",
  "ad86e680-2ca8-474d-886e-c3ba9ce283af",
  {
    firstName: "alex",
    lastName: "smith",
    email: "alex.smith@gmail.com",
  }
);
getEntityById(tableName, id)

Description

Get an entity by ID.

Parameters

Name Type Description Optional
tableName TableName (string) The name of the table
id EntityId (string) The ID of the entity to get

Return Value

Type Description
Entity (object) The entity

Example

const entity = await crudly.getEntityById(
  "users",
  "ad86e680-2ca8-474d-886e-c3ba9ce283af"
);
getEntities(tableName, options?)

Description

Get entities.

Parameters

Name Type Description Optional
tableName TableName (string) The name of the table
options GetEntitiesOptions The options for fetching entities (see below)

GetEntitiesOptions is an object with the following properties:

Name Type Description Optional Default
filters Filter[] (string[]) The filters to apply (see here for more details) []
orders Order[] (string[]) The orders to apply (see here for more details) []
limit number The page limit 20
offset number The page offset 0

Return Value

Type Description
Entity[] (object[]) The entities

Examples

const entities = await crudly.getEntities("users", {
  filters: ['firstName="alex"', 'lastName="smith"'],
});
const entities = await crudly.getEntities("users", {
  orders: ["firstName|asc", "lastName|desc"],
  limit: 1,
});
updateEntity(tableName, id, entity)

Description

Get entities.

Parameters

Name Type Description Optional
tableName TableName (string) The name of the table
id EntityId (string) The ID of the entity to update
entity Entity (object) The update to apply

Return Value

Type Description
Entity (object) The updated entity

Example

const entity = await crudly.updateEntity(
  "users",
  "0ede4735-3e24-4704-920b-bb50dfa70b9b",
  {
    lastName: "jones",
  }
);
deleteEntity(tableName, id)

Description

Delete an entity.

Parameters

Name Type Description Optional
tableName TableName (string) The name of the table
id EntityId (string) The ID of the entity to delete

Return Value

Type Description
void

Example

await crudly.deleteEntity("users", "0ede4735-3e24-4704-920b-bb50dfa70b9b");

Table

TBD

Rate limit

getRateLimit()

Description

Get rate limit information for a project.

Return Value

Type Description
RateLimit A project's rate limit information

RateLimit is an object with the following properties:

Name Type Description
dailyRateLimit number The number of daily API requests allowed for the project
currentRateUsage number The current rate usage for the project

Example

const { dailyRateLimit, currentRateUsage } = await crudly.getRateLimit();