App Rail Airtable
App Rail Airtable is a micro-framework based on Sinatra and Airrecord which faciliates use of Airtable as a backend for App Rail Apps. You can deploy a template repo to Heroku for fast start.
Visit App Rail Airtable Template and follow instructions.
Add this line to your application's Gemfile:
App Rail Airtable has two important concepts, models and servers. The App Rail Petshop provides useful examples.
App Rail Airtable makes the following assumptions
- Your App will connect to a single Airtable Base
- Your Airtable Base implements a normalised datamodel
- Your tables in Airtable are plural versions of the models you create in Ruby
API keys have account scope in Airtable so it is recommended to create a new account for each project so that API keys do not leak data, e.g. email@example.com. You can share the project with your main account so you don't need to login to separate accounts for each project.
To provide support for routes, models can implement
- ar_list_item (index)
- ar_stack (show)
- self.create_as_json (create)
In order to support authentication you should create a class (normally
User) and inherit from
AppRail::Airtable::AuthenticationRecord. Your table needs
Password Hash and
Access Token columns.
You should create a single server which extends
App Rail Airtable provides two helpers to generate routes
resources(name, only:) Creates routes that map to a table. It delegates from the route to a model method
authenticable_resources(name, , only:)
resources but also takes a block of routes. Those nested routes will all call the
authenticate! helper method before running. The
authenticate! helper will call a lookup helper
find_authenticatable_resource(access_token:) with the bearer token found in the
HTTP_AUTHORIZATION header, which should be used to look up the correct object or return nil if none is found (resulting in a 401 response).
The gem is available as open source under the terms of the MIT License.