Skip to content
This repository was archived by the owner on Sep 2, 2022. It is now read-only.

Commit fea84e1

Browse files
authored
Merge pull request #2 from apilytics/readme-changes
README and type import changes
2 parents b065d0d + fd24436 commit fea84e1

5 files changed

Lines changed: 27 additions & 16 deletions

File tree

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@
66
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
77
[![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/apilytics/apilytics-node/blob/master/LICENSE)
88

9+
Apilytics is a service that lets you analyze operational, performance and security metrics from your APIs without infrastructure-level logging.
10+
11+
<img src="https://www.apilytics.io/mock-ups/time-frame.gif" alt="Apilytics dashboard animation" width="600" height="300" />
12+
913
## Installation
1014

1115
1. Sign up and get your API key from https://apilytics.io - we offer a completely free trial with no credit card required!
1216

13-
2. Check installation directions for your specific framework:
17+
2. Continue with installation directions for your specific framework:
1418

15-
- [**Express**](./packages/express/README.md#installation)
19+
- [**Express** (`@apilytics/express`)](./packages/express/README.md#installation)
1620

17-
- [**Next.js**](./packages/next/README.md#installation)
21+
- [**Next.js** (`@apilytics/next`)](./packages/next/README.md#installation)
1822

19-
- [**Other Node.js Frameworks**](./packages/core/README.md#installation)
23+
- [**Other Node.js Frameworks** (`@apilytics/core`)](./packages/core/README.md#installation)

packages/core/README.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
[![node versions](https://img.shields.io/node/v/@apilytics/core)](#what-nodejs-versions-does-the-package-work-with)
99
[![license](https://img.shields.io/npm/l/@apilytics/core)](https://github.com/apilytics/apilytics-node/blob/master/packages/core/LICENSE)
1010

11+
Apilytics is a service that lets you analyze operational, performance and security metrics from your APIs without infrastructure-level logging.
12+
1113
Make sure to check out our out-of-the-box middleware packages first:
1214

13-
- [**Express**](../express/README.md#installation)
15+
- [**Express** (`@apilytics/express`)](../express/README.md#installation)
1416

15-
- [**Next.js**](../next/README.md#installation)
17+
- [**Next.js** (`@apilytics/next`)](../next/README.md#installation)
1618

1719
## Installation
1820

@@ -28,24 +30,28 @@ npm install @apilytics/core
2830
3. Set your api key and create a middleware which measures the execution time and sends the metrics:
2931
*A good practice is to securely store the API key as an environment variable.
3032
You can leave the env variable unset in e.g. development and test environments,
31-
the middleware will be automatically disabled if the key is `undefined`.*
33+
and make the middleware be disabled if the key is `undefined`.*
3234

3335
`my-apilytics-middleware.js`:
3436
```javascript
3537
import { milliSecondTimer, sendApilyticsMetrics } from '@apilytics/core';
3638

37-
const myApilyticsMiddleware = (/* ... */) => {
38-
const timer = milliSecondTimer();
39-
40-
// Call/await the request handler that the middleware wraps here.
39+
const myApilyticsMiddleware = async (req, handler) => {
40+
const apiKey = process.env.APILYTICS_API_KEY;
41+
if (!apiKey) {
42+
return await handler(req);
43+
}
4144

45+
const timer = milliSecondTimer();
46+
const res = await handler(req);
4247
sendApilyticsMetrics({
43-
apiKey: process.env.APILYTICS_API_KEY,
48+
apiKey,
4449
path: req.path,
4550
method: req.method,
4651
statusCode: res.statusCode,
4752
timeMillis: timer(),
4853
});
54+
return res;
4955
};
5056
```
5157

packages/express/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
[![node versions](https://img.shields.io/node/v/@apilytics/express)](#what-nodejs-versions-does-the-package-work-with)
99
[![license](https://img.shields.io/npm/l/@apilytics/express)](https://github.com/apilytics/apilytics-node/blob/master/packages/express/LICENSE)
1010

11+
Apilytics is a service that lets you analyze operational, performance and security metrics from your APIs without infrastructure-level logging.
12+
1113
## Installation
1214

1315
1. Sign up and get your API key from https://apilytics.io - we offer a completely free trial with no credit card required!

packages/express/src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { milliSecondTimer, sendApilyticsMetrics } from '@apilytics/core';
2-
import type { NextFunction, Request, Response } from 'express';
3-
import type { RequestHandler } from 'express-serve-static-core';
2+
import type { NextFunction, Request, RequestHandler, Response } from 'express';
43

54
export const apilyticsMiddleware = (
65
apiKey: string | undefined,
@@ -13,7 +12,6 @@ export const apilyticsMiddleware = (
1312

1413
return (req: Request, res: Response, next: NextFunction): void => {
1514
const timer = milliSecondTimer();
16-
1715
res.on('finish', () => {
1816
sendApilyticsMetrics({
1917
apiKey,
@@ -23,7 +21,6 @@ export const apilyticsMiddleware = (
2321
timeMillis: timer(),
2422
});
2523
});
26-
2724
next();
2825
};
2926
};

packages/next/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
[![node versions](https://img.shields.io/node/v/@apilytics/next)](#what-nodejs-versions-does-the-package-work-with)
99
[![license](https://img.shields.io/npm/l/@apilytics/next)](https://github.com/apilytics/apilytics-node/blob/master/packages/next/LICENSE)
1010

11+
Apilytics is a service that lets you analyze operational, performance and security metrics from your APIs without infrastructure-level logging.
12+
1113
## Installation
1214

1315
1. Sign up and get your API key from https://apilytics.io - we offer a completely free trial with no credit card required!

0 commit comments

Comments
 (0)