API Metering for Express Apps Using BigQuery

Hero Image

In the previous blog post, API Metering and Analytics for Early Stage Startups, I wrote about a simple yet flexible HTTP metering and analytics solution that uses BigQuery and Data Studio. This post will introduce the @fusebit/apimeter project, which provides an Express middleware you can use to capture API metering information from your Node.js app in BigQuery. You can add it to your app in less than ten minutes to derive insights from your API usage.

Enable API Metering in Your Express App

The @fusebit/apimeter project on Github contains detailed setup instructions for Google Cloud and Express. After you have pre-created the necessary BigQuery table and obtained the Google service account credentials, enabling metering in your app is as simple as adding the apimeter middleware.

First, add the @fusebit/apimeter module to your app:

npm install --save @fusebit/apimeter

Then in your app, add the following:

const app = require("express")();
const { apimeter } = require("@fusebit/apimeter");

projecId: "apimeter",
dataset: "dwh",
table: "apicalls",
credentials: require({path-to-the-google-service-credentials-file}.json’),

See @fusebit/apimeter to explain the various options you can pass to the middleware.

And that’s it! Once you run your app and HTTP API calls start coming in, metering data will be captured in the BigQuery table nearly instantaneously. You can run arbitrary SQL queries against it using the Google Cloud Console for BigQuery:

API Metering in BigQuery

If you want to create visual reports from this data, a great place to start is Google’s Data Studio. It is free to use and integrates natively with BigQuery. It is easy to create custom histograms or visual reports highlighting a particular aspect of your API usage:

API Metering solution for startups

API Metering analytics for startups

Here is a great tutorial for visualizing BigQuery data in Data Studio you can check out.

What is Fusebit?

Fusebit is a code-first integration platform that helps developers add integrations to their apps. It is code- and API-centric, hence the importance of HTTP API metering for us.

Fusebit is a platform for developers by developers. Follow us on Twitter @fusebitio for more great developer content, and check out other cool OSS projects at github.com/fusebit.


Related Content

10 March 2022
API Metering and Analytics for Early Stage Startups

This post will help you set up a simple metering and reporting system for the HTTP APIs of your app using BigQuery and DataStudio

14 March 2022
Streamline Funnel Analytics with Dynamic UTM Parameters

There is love-hate relationship with UTM parameters for performance marketing. Let’s explore a technical solution for automatically adding UTM tracking codes to all of your inbound links.

15 February 2022
Run Every Node.js Version in AWS Lambda

Run any version of Node.js in AWS Lambda within hours after release using custom AWS Lambda runtimes from Fusebit