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

@jorns/ng-crud-service

v1.1.1

Published

A simple CRUD service for Angular projects.

Readme

CrudService

A simple crud service for simple Angular applications.

Installation

npm install @jorns/ng-crud-service

Usage

Import the module into your AppModule. .forRoot Takes an object with an apiUrl property. Set the desired url for the API you consume and it will be prefixed on al your requests.

imports: [
    .......,
    CrudServiceModule.forRoot({
      apiUrl: 'https://example.com/api',
    })
]

Creating a service

Using a schematic:

ng generate @jorns/ng-crud-service:crud-service --name YourServiceName --path your/service/path

Custom:

Create a service and extend CrudService. Provide a resource prefix for your service which will be prepended to all your requests made. Inject the HttpClient to the contructor and provide to the baseclass constructor with super(http).

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { CrudService } from '@jorns/crud-service';

@Injectable({
  providedIn: 'root'
})
export class YourService extends CrudService {
  public resourcePrefix = 'todo';

  constructor(public http: HttpClient) {
    super(http);
  }
}

Using the service

Now you can import and use your service inside your components. Add the generic Type you expect to return from your API. Al CRUD methods return an Observable<T> of the given generic Type.

import { YourService } from 'your.service.ts';

this.myservice.create<Todo>().subscribe();
this.myservice.read<Todo[]>().subscribe();
this.myservice.update<Todo>().subscribe();
this.myservice.delete<Todo>().subscribe();

If the API's response has a different response i.e. { result: { todo }, message: 'Success' status: 200 } or an nested array with your results { result: [ { todo }, { todo }, { todo }, ], message: 'Success' status: 200 }

You can pass in your own Request class or interface if you need more then return a single class/interface or Array. For instance:

interface Request<T> {
  result: T;
  status: number;
  message: string;
  errors?: null|[];
};

`this.myservice.read<Request<Todo[]>>().subscribe();`

Adding route parameters

All CRUD methods take a Param type. This can be of type string|number|array. When you have a singel parameter you can pass in a string or number. When dealing with multipe url parameters you can add the in the right order into an array;

create<T>(formData?: FormDat a,param?: Param): Observable<T>
read<T>(param?: Param): Observable<T>
update<T>(param: Param, formData?: FormData): Observable<T>
delete<T>(param: Param): Observable<T>

this.myservice.update<Todo>([10,'edit'],formData).subscribe();
// Creates the url todo/10/edit
this.myservice.create<Todo>(formData,['category','5']).subscribe();
// Creates the url todo/category/5
this.myservice.delete<Todo>(10).subscribe();
// Creates the url todo/10

Extending the service

Of course you can add your own methods to the service you created when basic CRUD is not enough

export class YourService extends CrudService { public resourcePrefix = 'todo';

  constructor(public http: HttpClient) {
    super(http);
  }
  // for example return all todo's which belong to a category of 10.
  customMethod(id: number): Observable<IRequest<Todo[]>> {
    return this.http.get<IRequest<Todo[]>>(`/${this.resourcePrefix}/categories/10`);
  }
}

Using createUrlTree(params: Param) /** * for example return all todo's which belong to a category of 10, the params value * givin in this case is an Array. ['category','5']. * This method will build up the url including the resourcePrefix. */

otherCustomMethod(params: Param): Observable<IRequest<Todo[]>> {
  return this.http.get<IRequest<Todo[]>>(this.createUrlTree(params));
}