# ngx-cookie-api-service

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

Latest version **1.0.1** (published 2019-08-29) · 0 weekly downloads

## Install

```sh
npm install ngx-cookie-api-service
pnpm add ngx-cookie-api-service
yarn add ngx-cookie-api-service
bun add ngx-cookie-api-service
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2019-08-29 |
| First published | 2019-08-28 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 252.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Libin Prasanth |
| Maintainers | libinprasanth |
| Keywords | angular api call, angular 7 cookie, angular cookie, angular flicker, angular transferstate, angular 7 api call |

## Links

- npm: https://www.npmjs.com/package/ngx-cookie-api-service
- npm.io page: https://npm.io/package/ngx-cookie-api-service

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^1.9.0

## Recent versions

- 1.0.1 (latest) — 2019-08-29
- 0.0.3 — 2019-08-28

## README

# NGXCookieAPI

This library was generated with [Angular CLI](https://github.com/angular/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.

```sh
$ npm i ngx-cookie-api-service 
``` 

Import ngx-cookie-api in your app.module.ts file
```javascript
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"
```javascript
import { NGXCookieAPIService } from 'ngx-cookie-api-service';
constructor(private apiService: NGXCookieAPIService) {}
``` 
### API Calls
for GET method 
```javascript
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 
```javascript
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 
```javascript
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 
```javascript
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 
```javascript
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 
```javascript
this.apiService.set( 'test', 'Hello World' ); 
``` 

Get cookie 
```javascript
this.apiService.get('test');
``` 
Check cookie exist or not  
```javascript
this.apiService.check('test');
``` 
Delete cookie
```javascript
this.apiService.delete('test');
``` 
Delete All cookie
```javascript
this.apiService.deleteAll();
``` 
**Free Software, Hell Yeah!**

---
_Source: https://npm.io/package/ngx-cookie-api-service · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
