npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@webundsoehne/nestjs-util-restful

v3.0.14

Published

NestJS skeleton util library for restful applications.

Downloads

1,250

Readme


@webundsoehne/nestjs-util-restful

Version Downloads/week Dependencies semantic-release

Description

This is a collection of useful modules for creating a NestJS project. Mostly all of these modules are used by the in-house boilerplate of Web & Söhne.

Modules

Interceptors

Cache-Lifetime

The interceptor sets the cache-lifetime information of the response as it was configured. The configuration depends normally on project and environment.

It will add a function to the request state request.state.setCacheLifetime(), with that you can set a customized lifetime for each request.

Usage

import { RequestProfilerInterceptor } from '@webundsoehne/nestjs-util'

@Module({
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: RequestProfilerInterceptor
    }
  ]
})
class ServerModule implements NestModule {}

setCacheLifetime()

This function takes 2 parameters, where the second one is optional.

| Name | Type | Optional | Description | | ---------------- | ------- | -------- | ----------------------------------------------------------------------------------------------------------------------------- | | lifetime | Number | false | The lifetime of the cache in seconds | | useExpiresHeader | Boolean | true | If true the expiresHeader header will be set, otherwise the cacheControlHeader, be default it uses the configured value |

Configuration

The default values only exists in out skeleton project.

| Key | Type | Default | Description | | ---------------------------------- | ------- | --------------- | ------------------------------------------------------------------------------------ | | cacheLifetime.defaultExpiresHeader | Boolean | false | If true the expiresHeader header will be set, otherwise the cacheControlHeader | | cacheLifetime.defaultLifetime | Number | 0 | This value may set a default cache lifetime, if there was not set any before | | cacheLifetime.expiresHeader | String | 'Expires' | The header key for the expiresHeader | | cacheLifetime.cacheControlHeader | String | 'Cache-control' | The header key for the cacheControlHeader |

Request-Profiler

On debug logger level the request profile informs you when a request got started and when it was finished. It also logs down the response code information and how many seconds the request round-trip took.

Usage

import { RequestProfilerInterceptor } from '@webundsoehne/nestjs-util'

@Module({
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: RequestProfilerInterceptor
    }
  ]
})
class ServerModule implements NestModule {}

Example

[2020-01-01T12:00:00.000Z] [debug] [RequestProfilerInterceptor] - GET /v1/hello/world starting
[2020-01-01T12:00:00.025Z] [debug] [RequestProfilerInterceptor] - GET /v1/hello/world finished - 200 - took: 0.0250 sec

Providers

Swagger

Automatically creates a Swagger documentation out of your controllers. For detailed information about the how-to, take a deeper look at the Nest documentation.

Usage

import { SwaggerService } from '@webundsoehne/nestjs-util'

const app = await NestFactory.create<INestApplication>(ServerModule, new FastifyAdapter())
SwaggerService.enable(app, options)

Parameters

| Name | Required | Type | Description | | ------- | -------- | ---------------- | ----------------------------------------------------------------------- | | app | true | INestApplication | The Nest application on which the documentation should be created | | options | false | SwaggerOptions | Options for customize the default created document | | config | false | SwaggerConfig | Standard configuration, which are required for creating a documentation |

Types

SwaggerOptions

| Name | Required | Type | Description | | --------- | -------- | -------- | -------------------------------------------------------------- | | customize | false | Function | This function takes an DocumentBuilder modifies and returns it |

SwaggerConfig

| Name | Required | Type | Description | | ----------- | -------- | ------- | ----------------------------------- | | useHttps | true | Boolean | If the API is behind SSL encryption | | basePath | true | String | The base-path of the API | | path | true | String | The sub-path to reach the API | | title | true | String | The name of the API or the customer | | description | true | String | A description for the whole API |

Modules

Internal

This is a NestJS controller module for internal API endpoints, which can simply be added to each project. The controller provides you 2 endpoints /status and /changelog.

Usage

import { InternalModule } from '@webundsoehne/nestjs-util'

@Module({
  imports: [InternalModule]
})
class ServerModule implements NestModule {
  async configure(): Promise<any> {
    await setEnvironmentVariables()
  }
}

Configuration

| Key | Type | Default | Description | | ------------------- | ------ | -------------- | --------------------------------------------------- | | misc.changelogFile | String | 'CHANGELOG.md' | The filepath of the project's changelog information | | misc.lastUpdateFile | String | '.last-update' | The filepath of the projects's last update file |

Status

The status endpoint returns the current API version set during the process environment and the last modification of the .last-update in your root directory. The version will be set with the util function setEnvironmentVariables() read from package.json and the file will normally be generated/modified during the deployment process. You may change this value with the misc.lastUpdateFile configuration.

Changelog

This endpoint simply reads and responds with the CHANGELOG.md from your root directory. You can change the filepath with the configuration value misc.changelogFile.

Stay in touch