nest-utilities-client
TypeScript icon, indicating that this package has built-in type declarations

3.3.4 • Public • Published

Provides an extension on your HTTP services which interfaces with API's using the nest-utilities package.

NPM Downloads NPM Version

Basic usage

The package revolves around the CrudService. Extending this service will grant you methods to call upon the endpoints generated by nest-utilities as well as the available query parameters.

import { CrudService } from "nest-utilities-client";
import { IUser } from "../interfaces"

class UserService extends CrudService<IUser> {
  constructor() {
    super("http://localhost:3000/users");
  }
}

HTTP service

Out of the box the CrudService will supplement your extended class with a basic HTTP service to execute your calls. In a lot of cases you'll want to create generic error handlers and define headers to send along with your requests.

You can customize the HTTP service by creating a new class which extends the HTTP service offered by the package. In this new class you will be prompted to implement abstract methods which help you tailor the service with ease.

import { HttpService } from "nest-utilities-client";
import { messageService } from "../services";

class CustomHttpService extends HttpService {
  getHeaders(url: string, init: RequestInit) {
    return {
      "Authorization": localStorage.session
    };
  }

  onRequestError(error: Error) {
    messageService.notify(error.message);
  }
}
import { CrudService } from "nest-utilities-client";
import { CustomHttpService } from "../services";
import { IUser } from "../interfaces"

class UserService extends CrudService<IUser> {
  constructor() {
    super("http://localhost:3000/users", new CustomHttpService());
  }
}

Package Sidebar

Install

npm i nest-utilities-client

Weekly Downloads

8

Version

3.3.4

License

ISC

Unpacked Size

32 kB

Total Files

34

Last publish

Collaborators

  • martindrost