Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

NGX CRUD

CRUD services in Angular with effortless aborting, batching and caching.

Build Status Mutation Status Coverage Status NPM Version License Medium Article

Installation

npm install ngx-crud

Usage

Import the CrudModule and HttpClientModule inside your AppModule:

import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { CrudModule } from 'ngx-crud';

@NgModule(
{
	imports:
	[
		CrudModule,
		HttpClientModule
	]
})
export class AppModule
{
}

Extend the ExampleService from the CrudService:

import { Injectable } from '@angular/core';
import { CrudService } from 'ngx-crud';
import { ExampleInterface } from './example.interface';

import { environment } from '@env';

@Injectable()
export class ExampleService extends CrudService<ExampleInterface>
{
	protected apiUrl : string = environment.apiUrl;
	protected endpoint : string = environment.routes.example;
}

API

HTTP Operations

Fires a POST request to create a single resource:

crudService->create(body : BodyInterface, options? : OptionInterface) : Observable<T>

Fires a GET request to read a single resource:

crudService->read(id : IdType, options? : OptionInterface) : Observable<T>

Fires a GET request to find multiple resources:

crudService->find(options? : OptionInterface) : Observable<T[]>

Fires a PUT request to completely update a single resource:

crudService->update(id : IdType, body : BodyInterface, options? : OptionInterface) : Observable<T>

Fires a PATCH request to partially update a single resource:

crudService->patch(id : IdType, body : BodyInterface, options? : OptionInterface) : Observable<T>

Fires a DELETE request to delete a single resource:

crudService->delete(id : IdType, options? : OptionInterface) : Observable<T>

Fires a non-standard request:

crudService->request(method : MethodType, options? : OptionWithBodyInterface) : Observable<T | T[]>

HTTP Aborting

Enable aborting for the service:

crudService->enableAbort(method : MethodType = 'GET', lifetime : number = 2000) : this

Disable aborting for the service:

crudService->disableAbort() : this

Abort all requests of the service:

crudService->abort() : this

Abort a single request by its urlWithParams for enabled services:

abortService->abort(urlWithParams : string) : this

Abort many requests by their endpointUrl for enabled services:

abortService->abortMany(endpointUrl : string) : this

Abort all requests for enabled services:

abortService->abortAll() : this

Observe all requests for enabled services:

abortService->observeAll() : Observable<[string, AbortInterface]>

HTTP Batching

Fires multiple requests in parallel:

crudService->parallel(requestArray : ObservableInput<T>[]) : Observable<T[]>

HTTP Caching

Enable caching for the service:

crudService->enableCache(method : MethodType = 'GET', lifetime : number = 2000) : this

Disable caching for the service:

crudService->disableCache() : this

Flush all caches of the service:

crudService->flush() : this

Flush a single cache by its urlWithParams for enabled services:

cacheService->flush(urlWithParams : string) : this

Flush many caches by their endpointUrl for enabled services:

cacheService->flushMany(endpointUrl : string) : this

Flush all caches for enabled services:

cacheService->flushAll() : this

Observe all caches for enabled services:

cacheService->observeAll() : Observable<[string, CacheInterface]>

Service Shorthands

Clear the service:

crudService->clear()

Destroy the service:

crudService->destroy()

Service Options

Get the API URL of the service:

crudService->getApiUrl() : string

Set the API URL of the service:

crudService->setApiUrl(apiUrl : string) : this

Get the endpoint of the service:

crudServie->getEndpoint() : string

Set the endpoint of the service:

crudService->setEndpoint(endpoint : string) : this

HTTP Options

Get a single option of the service:

crudService->getOption<K extends keyof OptionInterface>(name : K) : OptionInterface[K]

Get the options of the service:

crudService->getOptions() : OptionInterface

Set a single option of the service:

crudService->setOption<K extends keyof OptionInterface>(name : K, value : OptionInterface[K]) : this

Set the options of the service:

crudService->setOptions(options : OptionInterface) : this

Clear a single option of the service:

crudService->clearOption<K extends keyof OptionInterface>(name : K) : this

Clear the options of the service:

crudService->clearOptions() : this

HTTP Headers

Get a single header of the service:

crudService->getHeader(name : string) : string

Get the headers instance of the service:

crudService->getHeaders() : HttpHeaders

Get values for a single header of the service:

crudService->getHeaderArray(name : string) : string[]

Set a single header of the service:

crudService->setHeader(name : string, value : string) : this

Set the headers instance of the service:

crudService->setHeaders(headers : HttpHeaders) : this

Set values for a single header of the service:

crudService->setHeaderArray(name : string, valueArray : string[]) : this

Append a single header to the service:

crudService->appendHeader(name : string, value : string) : this

Append values to a single header of the service:

crudService->appendHeaderArray(name : string, valueArray : string[]) : this

Clear a single header of the service:

crudService->clearHeader(name : string) : this

Clear the headers instance of the service:

crudService->clearHeaders() : this

HTTP Params

Get a single parameter of the service:

crudService->getParam(name : string) : string

Get the parameters instance of the service:

crudService->getParams() : HttpParams

Get values for a single parameter of the service:

crudService->getParamArray(name : string) : string[]

Set a single parameter of the service:

crudService->setParam(name : string, value : string) : this

Set the parameters instance of the service:

crudService->setParams(params : HttpParams) : this

Set values for a single parameter of the service:

crudService->setParamArray(name : string, valueArray : string[]) : this

Append a single parameter to the service:

crudService->appendParam(name : string, value : string) : this

Append values to a single parameter of the service:

crudService->appendParamArray(name : string, valueArray : string) : this

Clear a single parameter of the service:

crudService->clearParam(name : string) : this

Clear the parameters instance of the service:

crudService->clearParams() : this

About

CRUD services in Angular with effortless aborting, batching and caching

Topics

Resources

Releases

No releases published

Sponsor this project

 
Learn more about GitHub Sponsors

Packages

No packages published
You can’t perform that action at this time.