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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cms-libs/http

v1.0.10

Published

A lightweight, extensible HTTP utility library for Angular projects that simplifies API requests, error handling, file downloads, and caching. This library provides a base HTTP service (`BaseHttpService`) with common CRUD operations and a `CommonHttpSer

Readme

Angular Base HTTP Service Library

A lightweight, extensible HTTP utility library for Angular projects that simplifies API requests, error handling, file downloads, and caching.
This library provides a base HTTP service (BaseHttpService) with common CRUD operations and a CommonHttpService extension that integrates caching and global error handling via an event bus.


✨ Features

  • 🔗 Base URL support – automatically appends endpoint paths.
  • 📄 CRUD operationsget, post, put, patch, delete.
  • 💾 File downloads with file-saver.
  • 🔄 FormData conversion from JSON objects.
  • Centralized error handling with AppError.
  • 🛠 Customizable response mapping to adapt to any backend structure.
  • 🧩 Cache support with @ngneat/cashew.
  • 📢 Global error broadcasting with ng-event-bus.

📦 Installation

npm install @ngneat/cashew ng-event-bus @cms-libs/http

Make sure HttpClient is imported in your app.config.ts:

import { provideHttpClient, withInterceptors } from "@angular/common/http";
import { provideHttpCache, withHttpCacheInterceptor } from "@ngneat/cashew";
import { ApplicationConfig, provideZoneChangeDetection } from "@angular/core";
import { NgEventBus } from "ng-event-bus";

export const appConfig: ApplicationConfig = {
  providers: [
    provideZoneChangeDetection({ eventCoalescing: true }),
    // your app providers

    NgEventBus,
    provideHttpClient(withInterceptors([withHttpCacheInterceptor()])),
    provideHttpCache(),
  ],
};

🚀 Usage

1. Extend BaseHttpService

import { Injectable } from '@angular/core';
import { CommonHttpService } from '@cms-libs/http';

const BASE_URL = 'http://localhost:3000';

@Injectable()
export class UsersService extends BaseHttpService {
  constructor() {
    super(`${BASE_URL}/api/users`); // Base URL for users endpoints
  }
}

2. Perform API Requests

// inside a component or another service
this.usersService.get<User[]>()
  .subscribe({
    next: (res) => console.log('Users:', res.data),
    error: (err) => console.error('Error:', err),
  });

3. Download Files

this.usersService.download('export', 'users', 'csv')
  .subscribe(() => console.log('File downloaded!'));

4. Convert JSON to FormData

const formData = this.usersService.parseToFormData({ name: 'John', avatar: file });

🧩 Advanced: Using CommonHttpService

CommonHttpService extends BaseHttpService and adds:

  • Cache invalidation with Cashew.
  • Error broadcasting with NgEventBus.
import { Injectable } from '@angular/core';
import { CommonHttpService } from '@cms-libs/http';

const BASE_URL = 'http://localhost:3000';

@Injectable({ providedIn: 'root' })
export class ProductsService extends CommonHttpService {
  constructor() {
    super(`${BASE_URL}/api/products`);
  }
}

Invalidate Cache

this.productsService.invalidateCache();

Listen to Errors

this.eventBus.on('http:error').subscribe((error) => {
  console.error('Global HTTP error:', error);
  // display your error as you wish...
});

📑 Interfaces

BaseResponse<T>

export interface BaseResponse<T> {
  message?: string;
  success?: boolean;
  data: T;
  statusCode?: number;
  errors?: any[];
}

ListResponse<T>

export interface ListResponse<T> {
  data: T[];
  total: number;
  metadata?: any;
}

AppError

export class AppError {
  constructor(
    public message?: string,
    public cause?: any,
  ) {}
}

🔧 Customizing Response Mapping

If your backend response does not match BaseResponse, override mapResponse in BaseHttpService:

override mapResponse<T>(response: any) {
  return {
    data: response.data,
    success: response.status,
    statusCode: response.code,
    message: response.msg,
  };
}