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 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngx-nest-http

v0.1.0

Published

Angular HTTP client with Nest-style controllers, DTO validation, and declarative routing.

Readme

ngx-nest-http

Angular HTTP client with Nest-style controllers, DTO validation, and declarative routing.

Write API services the same way you write NestJS controllers: @ApiController, @GET, @POST, @Body, @Params, @Query. When the body is a class-validator DTO, it is transformed and validated before the request is sent.

Install

ng add ngx-nest-http

Or manually:

npm install ngx-nest-http class-validator class-transformer reflect-metadata

Setup

Import reflect-metadata once at app bootstrap:

import 'reflect-metadata';

Enable decorator metadata in tsconfig.json:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "useDefineForClassFields": false
  }
}

Register HttpClient and the library config:

import { provideHttpClient } from '@angular/common/http';
import { provideNestHttp } from 'ngx-nest-http';

export const appConfig = {
  providers: [
    provideHttpClient(),
    provideNestHttp({
      baseUrl: 'https://api.example.com',
      validation: {
        logErrors: !production,
        logMismatches: !production,
      },
    }),
  ],
};

Usage

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { IsInt, IsString } from 'class-validator';
import {
  ApiController,
  Body,
  GET,
  NestHttpClient,
  Params,
  POST,
  Query,
  request,
} from 'ngx-nest-http';

interface User {
  id: number;
  name: string;
}

export class CreateUserDto {
  @IsString()
  name!: string;

  @IsInt()
  age!: number;
}

@ApiController('api/users')
@Injectable({ providedIn: 'root' })
export class UsersApi extends NestHttpClient {
  @GET()
  list(@Query() query?: Record<string, unknown>): Observable<User[]> {
    return request();
  }

  @GET('/:id')
  getById(@Params('id') id: number): Observable<User> {
    return request();
  }

  @POST()
  create(@Body() dto: CreateUserDto): Observable<User> {
    return request();
  }
}

request() is only a type placeholder. @ApiController replaces the method at runtime.

You can also inject ApiExecutor and ApiValidationService in the constructor instead of extending NestHttpClient.

Decorators

| Decorator | Role | | --- | --- | | @ApiController(path, { baseUrl }) | Base path, optional host override | | @GET @POST @PUT @PATCH @DELETE | HTTP method + path | | @Params() / @Param() | Path params | | @Query() | Query params | | @Body() | Request body. Class DTOs are validated | | @Header({}) | Extra headers | | @ResponseType('blob' \| 'text' \| ...) | HttpClient response type | | @ReportProgress() | Upload/download progress events | | @Log() | Opt this method into request logging |

Logging

@Log() only opts a method in. The library emits a structured event; you decide how it looks.

onLog runs first, then the method hooks. Use skipGlobal: true when this method should not use the app-wide handler. If neither onLog nor method hooks are set, the event object is passed to logger (default console). Methods without @Log() emit nothing.

Hooks run in the API service injection context, so you can inject() your own Angular services. The same callbacks work with any SDK (Sentry, PostHog, Mixpanel, ...) — those stay app dependencies, not this library's.

Complete example:

import { inject, Injectable } from '@angular/core';
import { provideHttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { IsString } from 'class-validator';
import {
  ApiController,
  Body,
  GET,
  Log,
  NestHttpClient,
  POST,
  provideNestHttp,
  request,
  type NestHttpLogEvent,
} from 'ngx-nest-http';

@Injectable({ providedIn: 'root' })
export class AnalyticsService {
  track(name: string, data?: unknown): void {
    // send to your backend, PostHog, Sentry, Mixpanel, ...
  }
}

export const appConfig = {
  providers: [
    provideHttpClient(),
    provideNestHttp({
      baseUrl: 'https://api.example.com',
      onLog(event: NestHttpLogEvent) {
        inject(AnalyticsService).track(`http.${event.phase}`, {
          method: event.httpMethod,
          url: event.url,
          api: `${event.controller}.${event.methodName}`,
          error: event.error,
        });
      },
    }),
  ],
};

export class CreateUserDto {
  @IsString()
  name!: string;
}

interface User {
  id: number;
  name: string;
}

@ApiController('api/users')
@Injectable({ providedIn: 'root' })
export class UsersApi extends NestHttpClient {
  @GET()
  @Log()
  list(): Observable<User[]> {
    return request();
  }

  @POST()
  @Log({
    skipGlobal: true,
    onRequest: ({ body }) => {
      inject(AnalyticsService).track('user.create.attempt', {
        name: (body as CreateUserDto).name,
      });
    },
    onResponse: ({ response }) => {
      inject(AnalyticsService).track('user.create.ok', {
        id: (response as User).id,
      });
    },
    onError: ({ error }) => {
      inject(AnalyticsService).track('user.create.fail', error);
    },
  })
  create(@Body() dto: CreateUserDto): Observable<User> {
    return request();
  }

  @GET('/health')
  health(): Observable<{ ok: boolean }> {
    return request();
  }
}

list() uses the global onLog. create() skips it and sends its own events. health() has no @Log(), so it stays silent.

DTO transforms

import { Transform } from 'class-transformer';
import { toOptionalInt, toNullableInt, toOptionalIntArray } from 'ngx-nest-http';

@Transform(({ value }) => toOptionalInt(value))
age?: number;

Envelope types

This library does not ship a fixed API envelope. Map ApiResponse, pagination, and error codes in your app.

Development

npm start          # demo app
npm test           # library unit tests
npm run build      # library + ng-add schematic
npm run build:demo

CI runs on pull requests. Publishing to npm happens when a GitHub Release is published (NPM_TOKEN secret).

License

MIT