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

nestjs-http-builder

v1.0.4

Published

A NestJS HTTP service with builder pattern

Readme

A fluent builder pattern for making HTTP requests in NestJS

await this.apiService
      .createRequest()
      .setUrl("/users")
      .setMethod("POST")
      .setData(userData)
      .setRetryAttempts(3)
      .setValidationDto(UserDTO)
      .execute<UserDTO>();

Installation

npm install nestjs-http-builder

Setup

Import and configure the module in your app.module.ts:

import { Module } from "@nestjs/common";
import { ApiModule } from "nestjs-http-builder";

@Module({
  imports: [
    ApiModule.forRoot({
      // Optional axios config
      timeout: 5000,
      baseURL: "https://api.example.com",
    }),
  ],
})
export class AppModule {}

Usage Examples

Basic GET Request

@Injectable()
class UserService {
  constructor(private readonly apiService: ApiService) {}

  async getUsers() {
    return this.apiService
      .createRequest()
      .setUrl("/users")
      .setMethod("GET")
      .execute<User[]>();
  }
}

With Response Validation

class UserDTO {
  @IsString()
  name: string;

  @IsNumber()
  age: number;
}

@Injectable()
class UserService {
  async createUser(userData: any) {
    return this.apiService
      .createRequest()
      .setUrl("/users")
      .setMethod("POST")
      .setData(userData)
      .setValidationDto(UserDTO)
      .execute<UserDTO>();
  }
}

File Upload with Retry

@Injectable()
class UploadService {
  async uploadFile(file: Buffer) {
    return this.apiService
      .createRequest()
      .setUrl("/upload")
      .setMethod("POST")
      .setFormData({
        file: { file, fileName: "document.pdf" },
        description: "User document",
      })
      .setRetryAttempts(3)
      .execute();
  }
}

API Reference

RequestBuilder Methods

setUrl(url: string)

.setUrl('/api/users')

setMethod(method: HttpMethod)

.setMethod('GET')
// Supported: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'

setParams(params: Record<string, string | number | boolean>)

.setParams({
  page: 1,
  limit: 10,
  search: 'john',
  active: true
})

setHeaders(headers: Record<string, string>)

.setHeaders({
  'Authorization': 'Bearer your-token',
  'Custom-Header': 'value'
})

setData(data: any)

.setData({
  name: 'John Doe',
  email: '[email protected]',
  age: 30
})

setValidationDto<T>(dto: new () => T)

class UserDTO {
  @IsString()
  name: string;

  @IsEmail()
  email: string;

  @IsNumber()
  age: number;
}

.setValidationDto(UserDTO)

setResponseType(type: 'json' | 'arraybuffer')

// For regular JSON responses
.setResponseType('json')

// For file downloads
.setResponseType('arraybuffer')

setRetryAttempts(attempts: number)

.setRetryAttempts(3) // Will retry failed requests 3 times

setRetryDelay(delay: number)

.setRetryDelay(2000) // Wait 2 seconds between retries

setFormData(formData: Record<string, { file: Buffer; fileName: string } | string>)

.setFormData({
  file: {
    file: fileBuffer,
    fileName: 'document.pdf'
  },
  description: 'User profile document',
  category: 'profile'
})

execute<T>()

// With type safety
interface UserResponse {
  id: number;
  name: string;
  email: string;
}

const user = await apiService
  .createRequest()
  .setUrl("/users/1")
  .execute<UserResponse>();

// For array responses
const users = await apiService
  .createRequest()
  .setUrl("/users")
  .execute<UserResponse[]>();


## Best Practices

1. Always specify response types with execute<T>()
2. Use DTOs for structured data validation
3. Set appropriate retry attempts for unreliable endpoints
4. Handle errors appropriately in your application code
5. Use type-safe response handling

## License

MIT