# angular2-rest-client

> Angular2 REST Client

Latest version **3.0.5** (published 2018-09-18) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install angular2-rest-client
pnpm add angular2-rest-client
yarn add angular2-rest-client
bun add angular2-rest-client
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 3.0.5 |
| Published | 2018-09-18 |
| First published | 2016-10-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 42.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Mihai Billy Bălăceanu |
| Maintainers | gizm0bill |
| Keywords | angular2, http, rest, client |

## Links

- npm: https://www.npmjs.com/package/angular2-rest-client
- Repository: https://github.com/gizm0bill/angular2-rest-client
- Issues: https://github.com/gizm0bill/angular2-rest-client/issues
- npm.io page: https://npm.io/package/angular2-rest-client

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 3.0.5 (latest) — 2018-09-18
- 3.0.4 — 2018-08-10
- 3.1.0 — 2018-05-30
- 3.0.3 — 2018-04-06
- 3.0.2 — 2018-04-06
- 3.0.1 — 2018-02-01
- 3.0.0 — 2017-12-19
- 2.1.1 — 2017-07-05
- 2.1.0 — 2017-07-05
- 2.0.1 — 2017-05-11
- 2.0.0 — 2017-04-25
- 1.3.1 — 2017-04-19
- 1.3.0 — 2017-04-19
- 1.2.4 — 2017-04-12
- 1.2.3 — 2017-03-17
- … 15 more at https://npm.io/package/angular2-rest-client/versions

## README

# Angular2 REST Client
Angular2 REST Client inpsired by [angular2-rest](https://github.com/Paldom/angular2-rest)  
Tooling inspired by [angular2-webpack-starter](https://github.com/AngularClass/angular2-webpack-starter)

[![npm version](https://badge.fury.io/js/angular2-rest-client.svg)](https://badge.fury.io/js/angular2-rest-client)

## Installation
`npm install angular2-rest-client --save` / `yarn add angular2-rest-client --save` 

Uses deprecated `@angular/http`. Won't support `@angular/common/http` until it's stable and better documented.

## Example

```ts
// add base url from string
@BaseUrl('http://some.api/')
// add base url from json file
@BaseUrl('/config.json', 'base-url')
// add base url from function
// be sure to declare the function non-arrow style to have correct scope of this
@BaseUrl(function(){ return this.http.get('/config.json').map( (r: Response) => r.json()['base-url'] ) })
// only one of these per class 

// add some general headers
@Headers
({ 
  'X-Some-Common-Header': 'Some value', 
  'X-Some-Other-Common-Header': 'Some other value' 
})

// add custom error handler
@ApiError( (err, caught): Observable<string> => Observable.throw(new CustomError('BOOM!')) )

// you probably want to make this injectable
@Injectable()

// needst to extend AbstractApiClient
class ApiClient extends AbstractApiClient
{
  constructor( protected http: Http ) { super(http); }
  // specific method headers
  @Headers({ 'X-Some-Specific-Header': 'Some value' })
  // expected response content type
  @Type( ResponseContentType.Blob )
  // GET type request
  @GET('/resource/{id}')
  // add param to path: {id} is replaced by param value
  public read( @Path('Id') id: string ): Observable<Response> { return }

  // POST type request  
  @POST('/resource') 
  // add body fileds to the request
  public create( @Body('Name') name: string, @Body('Contents') file: File ): Observable<Response> { return }

  @POST('/resource')
  // can also add just a single param without any name, which will add the body as is to the request
  public create( @Body() body: string ): Observable<Response> { return }

  // PUT type request
  @PUT('/resource') 
  // add header from param to the request
  public update( @Header('X-Some-Author') author: number ): Observable<Response> { return }
  
  // DELETE type request
  @DELETE('/resource')
  // add query param: ?filter= 
  public delete( @Query('filter') filter: string ): Observable<Response> { return }
  
  // HEAD type request
  @HEAD('/resource') 
  public check(): Observable<Response> { return }
  
  // OPTIONS type request
  @OPTIONS('/resource') 
  public describe(): Observable<Response> { return }
}
```
## License

MIT

[npm-link]: https://badge.fury.io/js/angular2-rest-client.svg

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