Skip to content

apitoolkit/apitoolkit-express

Repository files navigation

APItoolkit's Logo APItoolkit's Logo

ExpressJS SDK

APItoolkit SDK Join Discord Server APItoolkit Docs

APItoolkit is an end-to-end API and web services management toolkit for engineers and customer support teams. To integrate your ExpressJS application with APItoolkit, you need to use this SDK to monitor incoming traffic, aggregate the requests, and then deliver them to the APItoolkit's servers.


Table of Contents


Installation

Kindly run the command below to install the SDK:

npm install apitoolkit-express

Configuration

Next, initialize APItoolkit in your application's entry point (e.g., index.js) like so:

import { APIToolkit } from "apitoolkit-express";
import express from "express";
import axios from "axios";

const app = express();
const port = 3000;

// IMPORTANT: apitoolkitClient must be declared
// BEFORE all controllers and middleware in your application.
const apitoolkitClient = APIToolkit.NewClient({ apiKey: "{ENTER_YOUR_API_KEY_HERE}" });

app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(apitoolkitClient.expressMiddleware);

app.get("/", (req, res) => {
  res.json({ hello: "Hello world!" });
});

// IMPORTANT: apitoolkitClient.errorHandler must be declared
// AFTER declaring apitoolkitClient.expressMiddleware
// and all controllers and BEFORE any other error middleware.
app.use(apitoolkitClient.errorHandler);

app.listen(port, () => console.log("App running on port: " + port));

Note

  • The {ENTER_YOUR_API_KEY_HERE} demo string should be replaced with the API key generated from the APItoolkit dashboard.
  • The apitoolkitClient.errorHandler must be after all controllers and before any other error middleware.

Important

To learn more configuration options (redacting fields, error reporting, outgoing requests, etc.), please read this SDK documentation.

Contributing and Help

To contribute to the development of this SDK or request help from the community and our team, kindly do any of the following:

License

This repository is published under the MIT license.