1.0.1 • Published 10 months ago

@justinjoram/request-interceptor v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@justinjoram/request-interceptor

A customizable request interceptor for NestJS applications that provides request logging and timing functionality.

Features

  • Request logging (method, URL, and body)
  • Response logging
  • Request timing measurements
  • Error logging
  • Configurable options

Installation

npm install @justinjoram/request-interceptor

Requirements

  • NestJS ^10.0.0
  • RxJS ^7.8.1

Usage

Basic Usage

import { RequestInterceptor } from '@justinjoram/request-interceptor';
import { Controller, UseInterceptors } from '@nestjs/common';

@UseInterceptors(new RequestInterceptor())
@Controller('example')
export class ExampleController {
  // Your controller methods
}

With Custom Options

import { RequestInterceptor } from '@justinjoram/request-interceptor';
import { Controller, UseInterceptors } from '@nestjs/common';

@UseInterceptors(new RequestInterceptor({
  logging: true,  // Enable/disable request and response logging
  timing: true    // Enable/disable request timing measurements
}))
@Controller('example')
export class ExampleController {
  // Your controller methods
}

Global Registration

import { RequestInterceptor } from '@justinjoram/request-interceptor';

// In your main.ts
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalInterceptors(new RequestInterceptor());
  await app.listen(3000);
}

Configuration Options

OptionTypeDefaultDescription
loggingbooleantrueEnables logging of requests and responses
timingbooleantrueEnables logging of request execution time

Logging Output

The interceptor provides the following log information:

  • Incoming request details (method, URL, body)
  • Response data
  • Request execution time (when timing is enabled)
  • Error details (if request fails)

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

1.0.1

10 months ago

1.0.0

10 months ago