npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

micro-airtable-api

v1.1.0

Published

[![Build Status](https://badgen.net/travis/rosszurowski/micro-airtable-api)](https://travis-ci.com/rosszurowski/micro-airtable-api)

Downloads

9

Readme

micro-airtable-api

Build Status

Quickly make an API from an Airtable. Use it as a database or CMS without any hassle.

Airtable offers a great API, but using it on the client-side exposes your API key, giving anyone read-write permissions to your data. micro-airtable-api proxies an Airtable API, hiding your API key and letting you control access (eg. marking an API as read-only).

Use Airtable as a cheap-and-easy CMS for simple blogs and sites :tada:

:construction: This project has not been thoroughly tested. Use at your own risk!

Usage

The simplest way to get started with your own Airtable proxy is via now. Setup and deploy with a single command:

$ now rosszurowski/micro-airtable-api -e AIRTABLE_BASE_ID=asdf123 -e AIRTABLE_API_KEY=xyz123

> Deployment complete! https://micro-airtable-api-asfdasdf.now.sh

Once deployed, you can read or edit your data at:

https://micro-airtable-api-asdasd.now.sh/v0/TableName

To update to a new version with potential bugfixes, all you have to do is run the now command again and change the URL you call in your app!

CLI

If you'd like to run a proxy on a different service, you can use the micro-airtable-api command-line. Install the package globally and run it:

$ npm i -g micro-airtable-api
$ AIRTABLE_BASE_ID=asdf123 AIRTABLE_API_KEY=xyz123 micro-airtable-api

> micro-airtable-api listening on http://localhost:3000

JS API

For more advanced configuration or to integrate with an existing http or express server, you can also install the package locally and pass the handler into your webserver:

$ npm i micro-airtable-api
const http = require('http');
const createAirtableProxy = require('micro-airtable-api');

const config = {
  airtableApiKey: 'YourApiKey',
  airtableBaseId: 'YourBaseId',
};

const server = http.createServer(createAirtableProxy(config));

Setup Notes

You can find your Base ID in the Airtable API docs and API key in your Airtable account settings.

Read below for all configurable options.

Configuration

micro-airtable-api is configurable both through the JS API and the CLI.

const http = require('http');
const createAirtableProxy = require('micro-airtable-api');

const config = {};

http.createServer(createAirtableProxy(config));

config.airtableBaseId (required)

The Base ID of the Airtable you want to connect to. You can find this in your Airtable API docs.

config.airtableApiKey (required)

Your personal account API key. You can find this in your account settings.

config.allowedMethods

An array of HTTP methods supported by the API. Use this to restrict how users can interact with your API. Defaults to all methods.

This maps directly to operations on Airtable:

  • GET allows reading lists of records or individual records
  • POST allows creating new records
  • PATCH allows updating existing records
  • DELETE allows removing records.

To create a read-only API, to use as a CMS:

createAirtableProxy({
  airtableBaseId: '...',
  airtableApiKeyId: '...',
  allowedMethods: ['GET'],
});

To create a write-only API, to use for collecting survey responses:

// A write-only API (eg. surveys)
createAirtableProxy({
  airtableBaseId: '...',
  airtableApiKeyId: '...',
  allowedMethods: ['POST'],
});

You can set table-specific permissions by passing in an object with table names as the keys.

If you were setting up a blog through Airtable, you could do the following:

createAirtableProxy({
  airtableBaseId: '...',
  airtableApiKeyId: '...',
  allowedMethods: {
    'Blog Posts': ['GET'],
    'Blog Comments': ['POST', 'PATCH', 'DELETE'],
  },
});

Note, the OPTIONS method is always allowed for CORS purposes.

CLI Options

The CLI exposes the above configuration options through environment variables for easy deployment.

$ AIRTABLE_BASE_ID=asdf123 AIRTABLE_API_KEY=xyz123 micro-airtable-api
  • AIRTABLE_BASE_ID (required) Same as config.airtableBaseId above
  • AIRTABLE_API_KEY (required) Same as config.airtableApiKey above
  • ALLOWED_METHODS Similar to config.allowedMethods above, except a comma-separated list instead of an array. For example, allow creating new records but not deleting by passing in a string without the delete method: ALLOWED_METHODS=GET,POST,PATCH. The CLI does not support table-specific permissions. Use the JS API if this is something you need.
  • READ_ONLY A shortcut variable to restrict the API to only GET requests. Equivalent to ALLOWED_METHODS=GET. Users of the API will be able to list all records and individual records, but not create, update, or delete.
  • PORT Sets the port for the local server. Defaults to 3000.

Contributing

Issues and PRs are welcome! If you'd like to contribute code, check out our guide on how to contribute.

License

MIT