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
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>",
});
The Crudly object exposes a number of methods for interacting with your project's data. These methods are documented below.
createEntity(tableName, entity)
Create an entity
Name |
Type |
Description |
Optional |
tableName |
TableName (string) |
The name of the table |
❌ |
entity |
Entity (object) |
The entity to create |
❌ |
Type |
Description |
EntityId (string) |
ID of the created entity |
Type |
Description |
CrudlyValidationError |
The provided entity did not fit the table schema |
CrudlyNotFoundError |
The table was not found |
CrudlyRateLimitExceededError |
Rate limit exceeded |
const entityId = await crudly.createEntity("users", {
firstName: "alex",
lastName: "smith",
email: "alex.smith@gmail.com",
});
createEntities(tableName, entities)
Create multiple entities
Name |
Type |
Description |
Optional |
tableName |
TableName (string) |
The name of the table |
❌ |
entities |
Entity[] (object[]) |
The entities to create |
❌ |
Type |
Description |
CrudlyValidationError |
One ore more provided entities did not fit the table schema |
CrudlyNotFoundError |
The table was not found |
CrudlyRateLimitExceededError |
Rate limit exceeded |
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)
Create an entity with specified ID.
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 |
❌ |
Type |
Description |
EntityId (string) |
The ID of the created entity |
Type |
Description |
CrudlyValidationError |
The provided entity did not fit the table schema |
CrudlyNotFoundError |
The table was not found |
CrudlyRateLimitExceededError |
Rate limit exceeded |
const entityId = await crudly.putEntity(
"users",
"ad86e680-2ca8-474d-886e-c3ba9ce283af",
{
firstName: "alex",
lastName: "smith",
email: "alex.smith@gmail.com",
}
);
getEntityById(tableName, id)
Get an entity by ID.
Name |
Type |
Description |
Optional |
tableName |
TableName (string) |
The name of the table |
❌ |
id |
EntityId (string) |
The ID of the entity to get |
❌ |
Type |
Description |
Entity (object) |
The entity |
const entity = await crudly.getEntityById(
"users",
"ad86e680-2ca8-474d-886e-c3ba9ce283af"
);
getEntities(tableName, options?)
Get entities.
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 |
Type |
Description |
Entity[] (object[]) |
The entities |
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)
Get entities.
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 |
❌ |
Type |
Description |
Entity (object) |
The updated entity |
const entity = await crudly.updateEntity(
"users",
"0ede4735-3e24-4704-920b-bb50dfa70b9b",
{
lastName: "jones",
}
);
deleteEntity(tableName, id)
Delete an entity.
Name |
Type |
Description |
Optional |
tableName |
TableName (string) |
The name of the table |
❌ |
id |
EntityId (string) |
The ID of the entity to delete |
❌ |
await crudly.deleteEntity("users", "0ede4735-3e24-4704-920b-bb50dfa70b9b");
TBD
getRateLimit()
Get rate limit information for a project.
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 |
const { dailyRateLimit, currentRateUsage } = await crudly.getRateLimit();