|
2 | 2 | <img src="https://apitoolkit.io/assets/img/logo-full.svg" alt="APIToolkit" width="250px" />
|
3 | 3 | </p>
|
4 | 4 |
|
5 |
| -APIToolkit Express Middleware is a middleware that can be used to monitor HTTP requests. It is provides additional functionalities on top of the open telemetry instrumentation which creates a custom span for each request capturing details about the request including request and response bodies. |
6 |
| - |
7 |
| -### Installation |
8 |
| - |
9 |
| -Run the following command to install the express js package from your projects root: |
10 |
| - |
11 |
| -```sh |
12 |
| -npm install apitoolkit-express |
13 |
| - |
14 |
| -``` |
15 |
| - |
16 |
| -### Project setup |
17 |
| - |
18 |
| -Intialize apitoolkit into your project like so: |
19 |
| - |
20 |
| -```js |
21 |
| -import express from 'express'; |
22 |
| -import { APIToolkit } from 'apitoolkit-express'; |
23 |
| - |
24 |
| -const app = express(); |
25 |
| -app.use(express.json()); |
26 |
| -app.use(express.urlencoded({ extended: true })); |
27 |
| -app.use( |
28 |
| - APIToolkit.middleware({ |
29 |
| - serviceName: 'my-service', |
30 |
| - redactHeaders: ['authorization', 'cookie'], |
31 |
| - redactResponseBody: ['$.creditCardNumber'], // jsonpath to redact credit card number from response body |
32 |
| - redactRequestBody: ['$.password'], // jsonpath to redact password from request body |
33 |
| - captureRequestBody: true, // capture request body and send it to your apitoolkit dashboard |
34 |
| - captureResponseBody: true // capture response body and send it to your apitoolkit dashboard |
35 |
| - }) |
36 |
| -); |
37 |
| - |
38 |
| -app.get('/hello/:name', (req, res) => { |
39 |
| - res.json({ message: `Hello ${req.params.name}!` }); |
40 |
| -}); |
41 |
| - |
42 |
| -// comes after all other route handlers |
43 |
| -app.use(APIToolkit.errorMiddleware()); |
44 |
| - |
45 |
| -app.listen(3000, () => { |
46 |
| - console.log('Server started on port 3000'); |
47 |
| -}); |
48 |
| -``` |
49 |
| - |
50 |
| -#### Quick overview of the configuration parameters |
51 |
| - |
52 |
| -An object with the following optional fields can be passed to the middleware to configure it: |
53 |
| - |
54 |
| -| Option | Description | |
55 |
| -| --------------------- | ------------------------------------------------------------------------------------------------- | |
56 |
| -| `debug` | Set to `true` to enable debug mode. | |
57 |
| -| `serviceName` | A defined string name of your application. | |
58 |
| -| `tags` | A list of defined tags for your services (used for grouping and filtering data on the dashboard). | |
59 |
| -| `serviceVersion` | A defined string version of your application (used for further debugging on the dashboard). | |
60 |
| -| `redactHeaders` | A list of HTTP header keys to redact. | |
61 |
| -| `redactResponseBody` | A list of JSONPaths from the response body to redact. | |
62 |
| -| `redactRequestBody` | A list of JSONPaths from the request body to redact. | |
63 |
| -| `captureRequestBody` | Default `false`, set to `true` if you want to capture the request body. | |
64 |
| -| `captureResponseBody` | Default `false`, set to `true` if you want to capture the response body. | |
65 |
| - |
66 |
| -<br /> |
67 |
| - |
68 |
| -> [!IMPORTANT] |
69 |
| -> |
70 |
| -> To learn more configuration options (redacting fields, error reporting, outgoing requests, etc.) and complete integration guide, please read this [SDK documentation](https://apitoolkit.io/docs/sdks/nodejs/expressjs/utm_campaign=devrel&utm_medium=github&utm_source=sdks_readme). |
| 5 | +> ⚠️ **Archived Repository** |
| 6 | +> This project has been archived and is no longer maintained here. |
| 7 | +> ➡️ Active development has moved to a: [**New Repository**](https://github.com/apitoolkit/apitoolkit-js/tree/main/packages/express) |
0 commit comments