# @ngflix/feign

> ### Feign makes writing http clients easier

Latest version **0.0.3** (published 2018-05-27) · 0 weekly downloads

## Install

```sh
npm install @ngflix/feign
pnpm add @ngflix/feign
yarn add @ngflix/feign
bun add @ngflix/feign
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2018-05-27 |
| First published | 2018-05-27 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 622.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | ngflix |

## Links

- npm: https://www.npmjs.com/package/@ngflix/feign
- npm.io page: https://npm.io/package/@ngflix/feign

## Dependencies (1)

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

## Recent versions

- 0.0.3 (latest) — 2018-05-27
- 0.0.2 — 2018-05-27
- 0.0.1 — 2018-05-27

## README

# @ngflix/feign

### Feign makes writing http clients easier

Feign is an Angular 5+ package for creating services that can be used to call backend parties, it's based on `HttpClientModule` provided by angular. Feign's first goal was reducing boilerplate.

### Installation

Install @ngflix/feign from npm:
`npm install @ngflix/feign --save`

### How does Feign work?

Create a service class and add some annotatons

```ts
// posts-feign.service.ts
import { FeignClient, RequestMapping, RequestBody, PathVariable } from '@ngflix/feign';
import { Observable } from 'rxjs';

@FeignClient({
  path: 'https://jsonplaceholder.typicode.com',
  name: 'postService'
})
export class PostService {
  @RequestMapping({ method: 'GET', value: 'posts' })
  public getAll(@RequestParam('order') order: 'desc' | 'asc', @RequestParam('date') date: Date): Observable<Post[]> {
    return null;
  }

  @RequestMapping({ method: 'POST', value: 'posts' })
  public createOne(@RequestBody post: Post): Observable<Post> {
    return null;
  }

  @RequestMapping({ method: 'GET', value: 'posts/{id}' })
  public getOne(@PathVariable('id') postId: string): Observable<Post> {
    return null;
  }
}

...

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  posts$: Observable<Posts[]>;

  constructor(private service: PostService) {
    this.posts$ = service.getAll('desc', new Date());
  }
}
```

To register the module within your application:

```ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { PostService } from './posts-feign.service';
import { NgFeignModule } from '@ngflix/feign';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, NgFeignModule.forRoot()],
  providers: [PostService],
  bootstrap: [AppComponent]
})
export class AppModule {}
```

## decorators:

#### @FeignClient

add meta data to service shuch as name, path, and interceptor

#### @RequestBody

The @RequestBody annotation indicates a paramer that should be used in the body of the request.

#### @Headers

Feign supports settings headers on requests either as part of the api or as part of the client depending on the use case.

#### @PathVariable

Replace a dynamic variable on the path by the parameter annotated.

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