# @kimaya/ngx-http-service

> This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.1.0.

Latest version **1.0.11** (published 2023-01-11) · 0 weekly downloads

## Install

```sh
npm install @kimaya/ngx-http-service
pnpm add @kimaya/ngx-http-service
yarn add @kimaya/ngx-http-service
bun add @kimaya/ngx-http-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.11 |
| Published | 2023-01-11 |
| First published | 2023-01-10 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 834 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ganesh.kumar |

## Links

- npm: https://www.npmjs.com/package/@kimaya/ngx-http-service
- npm.io page: https://npm.io/package/@kimaya/ngx-http-service

## Dependencies (1)

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

## Recent versions

- 1.0.11 (latest) — 2023-01-11
- 1.0.10 — 2023-01-10

## README

# HttpHandler

This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.1.0.

## How Install
    npm install @kimaya/ngx-http-service

#### Dependency 
<code>*You need to install dependencies manually*</code> 

[CookieStorage](https://www.npmjs.com/package/@kimaya/ngx-cookie-storage)
this is being used to store all cookies in this library.<br>
[AuthService](https://www.npmjs.com/package/@kimaya/ngx-auth-service)
this is being used for checking and fetching auth related settings.


## Plug into your application

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppComponent } from './app.component';
    import { HttpServiceModule } from 'ngx-http-service';
    
    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        HttpServiceModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

 
 ## How to use
 
 Inject into your <code>Component</code> or <code>Service</code>.
        
        import { Component } from '@angular/core';
        import { HttpService } from 'ngx-http-service';
        
        @Component({
          selector: 'app-root',
          templateUrl: './app.component.html',
          styleUrls: ['./app.component.scss']
        })
        
        export class AppComponent {
          constructor(private httpService: HttpService) {
          }
        }
        


 ## HttpService Configure
 
 User can configure some of keys for auth service as per project requirements.
   
 User need to set <code>HttpServiceConstants</code> keys for usages.
 
 *Need to set <code>serverUrl</code> .This will be used to hit api using httpService used as host for all default api*
 
 <code>ServerUrl is host </code><br>
 
 | Keys | Required | Default Value| Usage|
 |-------------|-------------|-----|-----|
 | serverUrl | true | null | used to store default host for all api end point which passed to HttpService functions |
 | headers | false | {} | Provide extra headers for all Http request including multipart request |

<br>

## Methods
        
#### get(endPoint: string, params?: object, body?: object, contentType?: string, backendUrl?: string ): Observable<any>;
        this.httpService.get(endPoint).subscribe();
to call http get method. In this method service will automatically append serverUrl from constant (host) and endPoint parameter.<br>
* endPoint: http api end point without host
* params: to set in param header [optional]
* body: to set in body header [optional]
* contentType: to set in content type header [optional]
* backendUrl: if you want to change host pass this parament [optional]
<hr>
     
#### getFromUrl(url: string, params?: object, body?: object, contentType?: string): Observable<any>;
        this.httpService.getFromUrl(endPoint).subscribe();
to call http get method. In this method service will not append serverUrl from constant (host) and will hit api based url you pass.<br>
* url: http api url with host and end point 
* params: to set in param header [optional]
* body: to set in body header [optional]
* contentType: to set in content type header [optional]
<hr>

#### getFromUrlWithoutHeader(url: string): Observable<any>;
        this.httpService.getFromUrlWithoutHeader(url).subscribe();
to call http get method. In this method, service will not add default header setting for http call.<br>
* url: http api url with host and end point 
* headers: HttpHeader- Custom Headers can be added. 
<hr>
        
#### post(endPoint: string, requestBody: object, params?: object, body?: object, contentType?: string, backendUrl?: string ): Observable<any>;
        this.httpService.post(endPoint, requestBody).subscribe();
to call http post method. In this method service will automatically append serverUrl from constant (host) and endPoint parameter.<br>
* endPoint: http api end point without host
* requestBody: request body in json
* params: to set in param header [optional]
* body: to set in body header [optional]
* contentType: to set in content type header [optional]
* backendUrl: if you want to change host pass this
parameter [optional]
<hr>
     
#### postFromUrl(url: string, requestBody: object, params?: object, body?: object, contentType?: string): Observable<any>;
        this.httpService.postFromUrl(url, requestBody).subscribe();
to call http post method. In this method service will not append serverUrl from constant (host) and will hit api based url you pass.<br>
* url: http api url with host and end point 
* requestBody: request body in json
* params: to set in param header [optional]
* body: to set in body header [optional]
* contentType: to set in content type header [optional]
<hr>

#### postFromUrlWithoutHeader(url: string, requestBody: object): Observable<any>;
        this.httpService.postFromUrlWithoutHeader(url, requestBody).subscribe();
to call http post method. In this method, service will not add default header setting for http call.<br>
* url: http api url with host and end point 
* requestBody: request body in json 
* headers: HttpHeader- Custom Headers can be added. 

<hr>
   
#### put(endPoint: string, requestBody: object, params?: object, body?: object, contentType?: string, backendUrl?: string ): Observable<any>;
        this.httpService.put(endPoint, requestBody).subscribe();
to call http put method. In this method service will automatically append serverUrl from constant (host) and endPoint parameter.<br>
* endPoint: http api end point without host
* requestBody: request body in json
* params: to set in param header [optional]
* body: to set in body header [optional]
* contentType: to set in content type header [optional]
* backendUrl: if you want to change host pass this
parameter [optional]
<hr>
     
#### putFromUrl(url: string, requestBody: object, params?: object, body?: object, contentType?: string): Observable<any>;
        this.httpService.putFromUrl(url, requestBody).subscribe();
to call http put method. In this method service will not append serverUrl from constant (host) and will hit api based url you pass.<br>
* url: http api url with host and end point 
* requestBody: request body in json
* params: to set in param header [optional]
* body: to set in body header [optional]
* contentType: to set in content type header [optional]
<hr>

#### putFromUrlWithoutHeader(url: string, requestBody: object): Observable<any>;
        this.httpService.putFromUrlWithoutHeader(url, requestBody).subscribe();
to call http put method. In this method, service will not add default header setting for http call.<br>
* url: http api url with host and end point 
* requestBody: request body in json
* headers: HttpHeader- Custom Headers can be added. 
<hr>

#### delete(endPoint: string, params?: object, body?: object, contentType?: string, backendUrl?: string ): Observable<any>;
        this.httpService.delete(endPoint).subscribe();
to call http delete method. In this method service will automatically append serverUrl from constant (host) and endPoint parameter.<br>
* endPoint: http api end point without host
* params: to set in param header [optional]
* body: to set in body header [optional]
* contentType: to set in content type header [optional]
* backendUrl: if you want to change host pass this
parameter [optional]
<hr>
     
#### deleteFromUrl(url: string, params?: object, body?: object, contentType?: string): Observable<any>;
        this.httpService.deleteFromUrl(endPoint).subscribe();
to call http delete method. In this method service will not append serverUrl from constant (host) and will hit api based url you pass.<br>
* url: http api url with host and end point 
* params: to set in param header [optional]
* body: to set in body header [optional]
* contentType: to set in content type header [optional]
<hr>

#### deleteFromUrlWithoutHeader(url: string): Observable<any>;
        this.httpService.deleteFromUrlWithoutHeader(url).subscribe();
to call http delete method. In this method, service will not add default header setting for http call.<br>
* url: http api url with host and end point 
* headers: HttpHeader- Custom Headers can be added. 
<hr>

#### multipart(endPoint: string, formData: FormData, methodType: HttpMethodTypes = HttpMethodTypes.GET, backendUrl?: string, responseType: HttpResponseTypes = HttpResponseTypes.json, authKey: string = 'Authorization'): Observable<any>;
        this.httpService.multipart(endPoint, formData).subscribe();
to call http method for multipart. In this method service will automatically append serverUrl from constant (host) and endPoint parameter.<br>
* endPoint: string 
* formData: FormData 
* methodType: HttpMethodTypes = HttpMethodTypes.GET // default get method
* backendUrl: string [optional]
* responseType: HttpResponseTypes = HttpResponseTypes.json // default JSON type
* httpHeaders: HttpHeader = null // default null
* authKey: string = 'Authorization' 
<hr>

#### multipartFromUrl(url: string, formData: FormData, methodType: HttpMethodTypes = HttpMethodTypes.GET, backendUrl: string, responseType: HttpResponseTypes = HttpResponseTypes.json, authKey: string = 'Authorization'): Observable<any>;
        this.httpService.multipartFromUrl(endPoint, formData).subscribe();
to call http method for multipart. In this method, service will not add default header setting for http call.<br>
* url: string 
* formData: FormData 
* methodType: HttpMethodTypes = HttpMethodTypes.GET // default get method
* responseType: HttpResponseTypes = HttpResponseTypes.json // default JSON type
* httpHeaders: HttpHeader = null // default null
* authKey: string = 'Authorization' 
<hr>

## Enums
We can use this enum values to pass parameters for multipart methods.

#### HttpResponseTypes
    enum HttpResponseTypes {
      'blob' = 'blob',
      'json' = 'json',
      'arraybuffer' = 'arraybuffer'
    }
    
#### HttpMethodTypes
    enum HttpMethodTypes {
      'GET' = 'GET',
      'POST' = 'POST',
      'PUT' = 'PUT'
    }  


## For more Information 
you can contact on <code>kumarganesh088@gmail.com</code>

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