ngx-cookie-api-service
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

NGXCookieAPI

This library was generated with Angular CLI version 7.2.0.

Main features of NGXCookieAPI!

  • Easy Api Call
  • Cookie options
  • Transferstate ( it will avoid page flicker and avoid api call twice when using SSR)

This library created for reduce coding. In this library included cookie, POST, GET, PUT, PATCH, DELETE.

We have used transferstate for GET Method, so you can use these data without call api again and again This libray created and tested with latest version of angular version 7.2.0.

Installation

Install the dependencies and devDependencies and start the server.

$ npm i ngx-cookie-api-service 

Import ngx-cookie-api in your app.module.ts file

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { EasyZoomModule } from 'angular-easy-zoom';
import { NGXCookieAPIModule, NGXCookieAPIService } from 'ngx-cookie-api-service';
 
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    NGXCookieAPIModule,
  ],
  providers: [
    NGXCookieAPIService
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Installation

In your component file import "NGXCookieAPIService"

import { NGXCookieAPIService } from 'ngx-cookie-api-service';
constructor(private apiService: NGXCookieAPIService) {}

API Calls

for GET method

let con = this.apiService.restGet('https://reqres.in/api','users',{"page":"3"}, {"X-CustomHttpHeader": "CUSTOM_VALUE"}, true, false);
    con.then(  
       (data) => { 
          console.log(data);
        }, 
        (error) => { 
        }
   );
  • 'https://reqres.in/api' - api base path
  • 'users' - api sub path
  • {"page":"3"} - parameter, it should be object format for GET method
  • {"X-CustomHttpHeader": "CUSTOM_VALUE"} - additional header, it should be object format
  • 5th parameter ( true ) is enable or disable transfersate - default value is true
  • 6th paramete ( false ) is keep transferstate value until page reload or not, if set true mean transferstate value won't removed untill page reload - defalult is false

for POST method

this
    .apiService
    .restPost('https://reqres.in/api', 'register', {"email": "eve.holt@reqres.in","password": "pistol"}, {"X-CustomHttpHeader": "CUSTOM_VALUE"}, (err, data) => {
       if (err) { 
          return;
        } 
    });

for PUT method

this
    .apiService
    .restPut('https://reqres.in/api', 'users/2', { "name": "morpheus", "job": "zion resident"}, {"X-CustomHttpHeader": "CUSTOM_VALUE"}, (err, data) => {
        if (err) { 
          return;
        }
        console.log(data);
    });

for PATCH method

this
    .apiService
    .restPatch('https://reqres.in/api', 'users/2', {"name": "morpheus","job": "zion resident"}, {"X-CustomHttpHeader": "CUSTOM_VALUE"}, (err, data) => {
        if (err) { 
          return;
        }
        console.log(data);
    });

for DELETE method

this
    .apiService
    .restDelete('https://reqres.in/api', 'users/2', {"name": "morpheus","job": "zion resident"}, {"X-CustomHttpHeader": "CUSTOM_VALUE"}, (err, data) => {
        if (err) { 
          return;
        }
        console.log(data);
    });

Cookie

Set cookie

this.apiService.set( 'test', 'Hello World' ); 

Get cookie

this.apiService.get('test');

Check cookie exist or not

this.apiService.check('test');

Delete cookie

this.apiService.delete('test');

Delete All cookie

this.apiService.deleteAll();

Free Software, Hell Yeah!

Package Sidebar

Install

npm i ngx-cookie-api-service

Weekly Downloads

1

Version

1.0.1

License

none

Unpacked Size

259 kB

Total Files

26

Last publish

Collaborators

  • libinprasanth