Have ideas to improve npm?Join in the discussion! »

    ngx-crud
    TypeScript icon, indicating that this package has built-in type declarations

    6.0.0-next.5 • Public • Published

    NGX CRUD

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

    Build Status Mutation Status Coverage Status NPM Version License Article Medium Playground StackBlitz

    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 : UniversalMethodType = '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 url for enabled services:

    abortService->abortMany(url : string) : this

    Abort all requests for enabled services:

    abortService->abortAll() : this

    Observe all requests for enabled services:

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

    HTTP Batching

    Fires multiple requests in parallel:

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

    HTTP Caching

    Enable caching for the service:

    crudService->enableCache(method : UniversalMethodType = '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 url for enabled services:

    cacheService->flushMany(url : string) : this

    Flush all caches for enabled services:

    cacheService->flushAll() : this

    Observe all caches for enabled services:

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

    HTTP Observing

    Enable observing for the service:

    crudService->enableObserve(method : UniversalMethodType = 'ANY', lifetime : number = 1000) : this

    Disable observing for the service:

    crudService->disableObserve() : this

    Complete all observers for enabled services:

    observeService->completeAll() : this

    Observe all requests for enabled services:

    observeService->observeAll() : Observable<boolean>

    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 Context

    Get the context by token:

    crudService->getContextByToken(token : HttpContextToken<ContextInterface>) : HttpContext

    Get the context instance of the service:

    crudService->getContext() : HttpContext

    Set the context by token:

    crudService->setContextByToken(token : HttpContextToken<ContextInterface>, value : ContextInterface) : this

    Set the context instance of the service:

    crudService->setContext(context : HttpContext) : this

    Clear the context by token:

    crudService->clearContextByToken(token : HttpContextToken<ContextInterface>) : this

    Clear the context instance of the service:

    crudService->clearContext() : 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

    Misc

    Get the http client:

    crudService->getHttpClient() : HttpClient

    Create the url of the request:

    createUrl(apiUrl : string, endpoint : string, id? : number | string) : string

    Install

    npm i ngx-crud

    DownloadsWeekly Downloads

    75

    Version

    6.0.0-next.5

    License

    MIT

    Unpacked Size

    526 kB

    Total Files

    59

    Last publish

    Collaborators

    • avatar