Apilytics is a service that lets you analyze operational, performance and security metrics from your APIs easily.
-
Sign up and get your API key from https://apilytics.io - we offer a completely free trial with no credit card required!
-
Install this package:
yarn add @apilytics/next
# OR
npm install @apilytics/next- Enable the middleware and set your API key:
A good practice is to securely store the API key as an environment variable. You can leave the env variable unset in e.g. development and test environments, the middleware will be automatically disabled if the key isundefined.
pages/api/my-route.js:
import { withApilytics } from '@apilytics/next';
const handler = async (req, res) => {
// ...
};
// Ideally the outermost middleware that you wrap your handler with.
export default withApilytics(handler, process.env.APILYTICS_API_KEY);- No. The middleware does all of its requests to the Apilytics API in the background, by using promises without awaiting them, so it will not slow down your normal request handling.
- None besides Next.js itself.
@apilytics/nextis tested to work on all the currently supported versions of Node: 12, 14, 16, and 17.