https://github.com/pspeter3/airtable-lite
Light weight type safe Airtable API client
https://github.com/pspeter3/airtable-lite
airtable airtable-api typescript
Last synced: 3 months ago
JSON representation
Light weight type safe Airtable API client
- Host: GitHub
- URL: https://github.com/pspeter3/airtable-lite
- Owner: pspeter3
- License: mit
- Created: 2021-02-15T16:07:34.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2023-01-07T05:29:27.000Z (over 3 years ago)
- Last Synced: 2025-10-06T14:58:53.104Z (9 months ago)
- Topics: airtable, airtable-api, typescript
- Language: TypeScript
- Homepage: https://pspeter3.github.io/airtable-lite/
- Size: 1000 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# airtable-lite
Light weight type safe Airtable API client
## Requirements
- Fetch
- ES6
- Airtable Account
## Installation
- Find your Airtable API Key. Look [here](https://support.airtable.com/hc/en-us/articles/219046777-How-do-I-get-my-API-key-) for instructions.
- Find your Base ID from the [Airtable API](https://airtable.com/api) documentation.
- Install the library `npm install airtable-lite`.
## Examples
```ts
import {
Airtable,
AirtableDirection,
AirtableError,
createAirtableClient,
} from "airtable-lite";
// Constants
const API_KEY = "secret";
const BASE_ID = "baseID";
// A few ways to create tables
const users = new Airtable<{ Name: string; Notes: string }>(
API_KEY,
BASE_ID,
"User"
);
const comments: Airtable<{ Name: string; User: string }> = createAirtableClient(
API_KEY
)(BASE_ID)("Comments");
const createBase = createAirtableClient(API_KEY);
const createTable = createBase(BASE_ID);
const likes = createTable<{ Name: string; Count: number }>("Likes");
// CRUD operations
const { id } = await users.create({ Name: "Test" });
await users.update(id, { Notes: "Safe" });
await users.update(id, { Notes: "Destructive" }, true);
const user = await users.find(id);
await users.delete(id);
// Bulk operations
await comments.bulkCreate([{ Name: "First!", User: id }, { Name: "Test" }]);
await comments.bulkUpdate([
{ id: "1", fields: { Name: "Second!" } },
{ id: "2", fields: { User: id } },
]);
await comments.bulkDelete(["1", "2"]);
// Select
await likes.select({ maxRecords: 10 });
// Project with type safety.
// The `fields` option will only take valid field names.
// The records will only have 'Name' available in this example.
await likes.select({ fields: ["Name"] });
// Sort with type safety.
// The `sort` option will only take valid field names.
await likes.select({
sort: [
{ field: "Name" },
{ field: "Count", direction: AirtableDirection.Descending },
],
});
// Also have type safe error handling
try {
await users.find("1");
} catch (err) {
if (err instanceof AirtableError) {
console.log(err.status, err.type, err.message);
}
}
```
## Documentation
TypeDoc documentation can be found on the [project homepage](https://pspeter3.github.io/airtable-lite/).