My tool-kit for tiny APIs

  • I only want to pay for what I use (scale-to-zero)
  • I don’t have a lot of time available for learning or building (no steep learning curves without substantial time-savings)
  • I don’t have time for maintenance activities (no patching servers, automated scale-up)
  • I’m not a good UI designer or front end engineer (design systems are great)

TL;DR

  • Open API (and Postman)
  • AWS API Gateway
  • Google Firebase Cloud Functions with Node.js and Express
  • Google Firebase
  • Github Actions

The business problem

  • those that solve a problem I have, and it would be cool if I could figure out a way to monetise them one day
  • those that solve a problem I care about, and it would be cool if I could offer them up for free without it costing me too much along the way

Three problems and then some

  • I only want to pay for what I use (scale-to-zero)
  • I don’t have a lot of time available for learning or building (no steep learning curves without substantial time-savings)
  • I don’t have time for maintenance activities (no patching servers, automated scale-up)

The server-side execution

app.get('/authority', async (req, res) => {
let docRef = db.collection('councils');
const snapshot = await docRef.get();
res.status(200).send(snapshot.docs.map(doc=>doc.id));
});

The public facing API

  • I need a way to issue API keys to consumers and manage usage limits if required
  • I need a way to measure usage by consumers
  • I need a way to prevent misuse through tools like “throttling” (rate-limiting)
  • I don’t want to have to keep API documentation up to date manually and separately from the contract in the code

Deployment

const arn = 'arn:aws'; // ...
const certificate = acm.Certificate.fromCertificateArn(this, 'Certificate', arn);
const definition = apigateway.ApiDefinition.fromAsset('../nz-recycling-advanced-prod-oas30-apigateway.json');
const subdomain = 'nz-recycling.api.cronin.nz';
const api = new apigateway.SpecRestApi(this, "recycling-api", {
deploy: false,
apiDefinition: definition,
domainName: {
domainName: subdomain,
certificate: certificate,
}
});
const zone = route53.HostedZone.fromHostedZoneAttributes(this, 'CroninDomain', {
zoneName: 'cronin.nz',
hostedZoneId: 'Z14C5CS' //...,
});
const deployment = new apigateway.Deployment(this, 'recycling-deployment', { api });
new apigateway.Stage(this, 'prod', {
deployment,
stageName: 'prod',
variables: { 'authToken': 'my-secret-token' },
loggingLevel: apigateway.MethodLoggingLevel.INFO,
});
new route53.ARecord(this, 'CustomDomainAliasRecord', {
zone,
recordName: subdomain,
target: route53.RecordTarget.fromAlias(new targets.ApiGateway(api))
});
name: Gateway buildon:
push:
branches: [ main ]
paths:
- 'gateway/**'
jobs:
aws_cdk:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: cdk deploy
uses: youyo/aws-cdk-github-actions@v2
with:
cdk_subcommand: 'deploy'
cdk_args: '--require-approval never'
actions_comment: false
working_dir: 'gateway'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: 'us-west-2'
name: Functions buildon:
push:
branches: [ main ]
paths:
- 'functions/**'
- '.github/workflows/functions.yml'
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@master
- name: Install Dependencies
run: |
cd functions
npm install
- name: Deploy to Firebase
uses: w9jds/firebase-action@master
with:
args: deploy --only functions
env:
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}

Summary

--

--

--

Technology leader for Xero in Auckland, New Zealand, former start-up founder, father of two, maker of t-shirts and small software products

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Things to avoid while using Golang plugins

Voifone | Multipurpose VOIP WordPress Theme

19coders

Analyzing Twitter Feeds Using Hive

[Guide #001] ✨ RAYS MINING ⛏

Simple Introduction to Python and Anaconda

Why RudderStack Used Postgres Over Apache Kafka for Streaming Engine

How To Create A WordPress Popup Contact Form (Open Form In Popup)

19coders

SVG Donut Charts — Free Download

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gareth Cronin

Gareth Cronin

Technology leader for Xero in Auckland, New Zealand, former start-up founder, father of two, maker of t-shirts and small software products

More from Medium

AWS Data Exchange for APIs, How to Protect Your APIs, APIs Aren’t Just for Developers

Thoughts about low/no code and vendor lock-in

Boost Your Airtable Automation with AWS Lambda + API Gateway

Perfecting Site Speed Optimization Part II: How to Get 100% Performance Ranking