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");
app.use(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:
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:
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.