# exc-rest

> ExcRestModule implements the ExcRestService.

Latest version **1.0.8** (published 2020-10-20) · 0 weekly downloads

## Install

```sh
npm install exc-rest
pnpm add exc-rest
yarn add exc-rest
bun add exc-rest
```

## 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.8 |
| Published | 2020-10-20 |
| First published | 2018-11-14 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 380.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | markus.heiss.excon.com, risatronex |

## Links

- npm: https://www.npmjs.com/package/exc-rest
- npm.io page: https://npm.io/package/exc-rest

## Dependencies (1)

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

## Recent versions

- 1.0.8 (latest) — 2020-10-20
- 1.0.7 — 2020-09-18
- 1.0.6 — 2020-09-18
- 1.0.5 — 2020-09-18
- 1.0.4 — 2020-03-24
- 1.0.3 — 2020-03-24
- 1.0.2 — 2020-03-23
- 1.0.0 — 2020-02-19
- 0.4.3 — 2020-01-23
- 0.4.2 — 2020-01-20
- 0.4.1 — 2019-11-19
- 0.4.0 — 2019-09-10
- 0.3.2 — 2019-08-16
- 0.3.1 — 2019-05-15
- 0.3.0 — 2019-05-13
- … 12 more at https://npm.io/package/exc-rest/versions

## README

# Documentation


## Module Exc-Rest
ExcRestModule implements the ExcRestService.

### Setup
To use ExcRestService you have to do preparations in your project.

1. Ensure that the exc-core module is included as dependency in package.json
2. Ensure that the exc-rest module is included as dependency in package.json
3. Setup app.module.ts file 
``` @typescript

import {environment} from '../environments/environment';
import {HttpClient, HttpClientModule} from '@angular/common/http';
import {ExcCoreModule} from 'exc-core';
import {ExcRestModule} from 'exc-rest';
//...

@NgModule({
declarations:[],
imports:[
  HttpClientModule
  ExcRestModule
  //...
],
entryComponents:[],
providers:[],
bootstrap: [AppComponent]
})


export class AppModule{
  env = environment
  constuctor(){
    ExcCoreModule.RegisterConfig('Environment',_self.env);
  }
  //...
}
```

4. Setup app.component.ts file
``` @typescript

import {ExcCoreModule} from 'exc-core';
import {ExcRestModule} from 'exc-rest';
//...
export class AppComponent  implements OnInit{
//...
  constructor(private excRestService:ExcRestService){  
  }
}
```

## ExcRestService
The ExcRestService is the service for standard communication with the EXCON REST Apis. 

### Parameter definition
- `name` Defines the name of the endpoint in environment.ts under Endpoints. 
- `pObj` Defines an object for replacement of placeholders in URL
- `url` Defines the url generated by computedUrl
- `data` Defines the data that will be sent to the webservice
- `conf` Defines the http config used by rest call. Detailed information under this paragraph
- `isbc` Defines a call is a background call or not. It is used for global activity indicator. Background calls doesn't have an effect to indicator.
- `fullResponse` Used by delete and put. By default these methods return the fullResponse. If you use this function please manually set parameter to false. The default behavior will be set to false in future.

### Config object
- `MetaInfo:*object*` Defines the definition for filter, paging and sorting for webservice.
- `OnProgress(progress):*function*` Method that could be set to get information about progress of the call.
- `export:*Boolean*`  If set to true the call is marked as download and the webservice result is downloaded as file.


### Members
#### Methods

##### Publics
All public methods have a default behavior. So the automatically triggers messages for success and error or are preprocessing data.

|Method|Return|Description|
| --- | --- | --- |
| computeUrl(name:*string*,pObj:*object*)|**string**|Gets a computed url from config and replaces placeholders with values of pObj|
| delete(url:*string*,data:*any*,conf:*object*,fullResponse:*Boolean*(true))|**Observable<any>**|Sends an HTTP DELETE request to given URL|
| get(url:*string*,conf:*object*)|**Observable<any>**|Sends an HTTP GET request to given URL|
| sget(url:*string*,id:*string*,conf:*object*)|**Observable<any>**|Sends an HTTP GET request to given URL. The given ID is used to identify the last call of an id. So it is possible to get the last valid call. At response you can check the flag valid to only use the last answer for the given id |
| post(url:*string*,data:*any*,conf:*object*)|**Observable<any>**|Sends an HTTP POST request to given URL|
| put(url:*string*,data:*any*,conf:*object*,fullResponse:*Boolean*(true))|**Observable<any>**|Sends an HTTP PUT request to given URL|
| base64ToArrayBuffer(base64:*string*)|*Uint8Array*|Convert a base64 string to an arraybuffer|
| exportBase64(base64String:*string*,contentType:*string*,filename:*string*)|*void*|starts a download of the base64 string with given contentType and filename|
| exportBuffer(uInt8Array:*Uint8Array*,contentType:*string*,filename:*string*)|*void*|starts a download of the UInt8Array with given contentType and filename|


##### Internals

Internal call shouldn't be used for default behavior. The internal methods have no default behavior.

|Method|Return|Description|
| --- | --- | --- |
| _deleteInternal(url:*string*,data:*any*,conf:*object*,isbc:*Boolean*)|**Observable<any>**|Sends an HTTP DELETE request to given URL|
| _getInternal(url:*string*,conf:*object*,isbc:*Boolean*)|**Observable<any>**|Sends an HTTP GET request to given URL|
| _putInternal(url:*string*,data:*any*,conf:*object*,isbc:*Boolean*)|**Observable<any>**|Sends an HTTP PUT request to given URL|
| _postInternal(url:*string*,data:*any*,conf:*object*,isbc:*Boolean*)|**Observable<any>**|Sends an HTTP POST request to given URL|


###### get example
```typescript
import {ExcCoreModule} from './exc-core.module';

const excRest = ExcCoreModule.Services().ExcRest;
// OrderList: {uid}/order/:ordID
let obs = excRest.get(excRest.computeUrl('OrderDetails',{ordID:14}),{MetaInfo:{}});
obs.subscribe(result=>{
  //doIt
})

```

###### sget example
```typescript
import {ExcCoreModule} from './exc-core.module';

const excRest = ExcCoreModule.Services().ExcRest;
// OrderList: {uid}/order
let obs = excRest.sget(excRest.computeUrl('OrderList',{key:'value',fts:'full-text-search-value'}),'MagicList',{MetaInfo:{}});
obs.subscribe(result=>{
  if(result.valid)
    {
       //doIt
    }
 
})

```

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