# @vts-kit/angular-network

> Collection of useful network utillities to be integrated with Angular project

Latest version **1.0.3** (published 2023-03-17) · Viettel Solutions license · 0 weekly downloads

## Install

```sh
npm install @vts-kit/angular-network
pnpm add @vts-kit/angular-network
yarn add @vts-kit/angular-network
bun add @vts-kit/angular-network
```

## 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.3 |
| Published | 2023-03-17 |
| First published | 2022-11-09 |
| Weekly downloads | 0 |
| License | Viettel Solutions |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 306.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Viettel Solutions |
| Maintainers | vts-contributor |

## Links

- npm: https://www.npmjs.com/package/@vts-kit/angular-network
- Repository: https://github.com/vts-contributor/vts-kit-angular-utils
- Homepage: https://github.com/vts-contributor/vts-kit-angular-utils#readme
- Issues: https://github.com/vts-contributor/vts-kit-angular-utils/issues
- npm.io page: https://npm.io/package/@vts-kit/angular-network

## Dependencies (1)

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

## Recent versions

- 1.0.3 (latest) — 2023-03-17
- 1.0.2 — 2022-11-11
- 1.0.1 — 2022-11-10
- 1.0.0 — 2022-11-09

## README

# VTS Kit Angular Utilities (Network)

## Installation

```
npm install @vts-kit/angular-network
```

## Guideline

### RestClient

RestClient provide abilities to interact with RESTful API through builder pattern.

**Import**

```
// app.module.ts
import { VtsRestModule, RestClientOptions, VtsRestModuleConfig } from "@vts-kit/angular-network"

// Default config
const NETWORK_MODULE_CONFIG: VtsRestModuleConfig = {
  defaultConfig: new RestClientOptions()
    .setBaseUrl('https://<base_api_url>')
    .setHeader('<key>', '<value>')
    .setParam('<key>', '<value>')
    .setRetry(3),
};

@NgModule({
  declarations: [AppComponent],
  imports: [
    ...,
    VtsRestModule.forRoot(NETWORK_MODULE_CONFIG)
    // Without default config
    // VtsRestModule.forRoot()
  ]
})
export class AppModule {}
```

**Usage**

Pattern:

```
client
  .setHeader("key", "value")
  .setTimeout(60000)
  ... // More builder
  .obserseBody() // or obserseEvents() or obserseResponse()
  .get("<path or url>") // or post, patch, put, options, delete
  .subscribe(...)
```

Example:

```
// name.any.ts
@Injectable({
  providedIn: 'root',
})
export class Service {
  constructor(private client: RestClient) {}

  callApi() {
    this.client
      .obserseBody()
      .get<Post[]>('/posts')
      .subscribe({
        next: (d) => console.log(d[0].title),
        error: (e) => console.log(e),
      });
  }
}
```

---

### NetworkUtils

Provide some useful function to interact with network state, data...

| No  | Function Name | Description                          | Output              |
| --- | ------------- | ------------------------------------ | ------------------- |
| 1   | online$       | Return observable to network status  | Observable<boolean> |
| 2   | isOnline      | Return current network active status | boolean             |

---
_Source: https://npm.io/package/@vts-kit/angular-network · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
