🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

ng2-http-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng2-http-wrapper

Angular2 HTTP wrapper for REST client services

0.0.4-alpha
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

ng2-http-wrapper

npm version devDependency Status peerDependency Status GitHub issues GitHub stars GitHub license

Demo

https://hboylan.github.io/ng2-rest/demo/

Table of contents

About

Angular2 HTTP wrapper for REST client services

Installation

Install through npm:

npm install --save ng2-http-wrapper

Then use it in your app like so:

// demo.module.ts
import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {RESTModule} from 'ng2-http-wrapper';
import {Demo} from './demo.component';
import {DemoService} from './demo.service';

@NgModule({
  declarations: [Demo],
  imports: [BrowserModule, RESTModule],
  bootstrap: [Demo],
  providers: [DemoService]
})
export class DemoModule {}
// demo.service.ts
import {Injectable} from '@angular/core';
import {Http, Request, Response} from '@angular/http';
import {RESTClient, BaseUrl, DefaultHeaders, GET, POST, Body, Query, Produces} from 'ng2-http-wrapper';
import {Observable} from 'rxjs/Observable';

@Injectable()
@BaseUrl('https://jsonplaceholder.typicode.com')
@DefaultHeaders({
  'Accept': 'application/json',
  'Content-Type': 'application/json'
})
export class DemoService extends RESTClient {

  constructor(protected http: Http) {super(http)}

  protected requestInterceptor(req: Request) {}

  protected responseInterceptor(res: Observable<Response>): Observable<Response> {
    return res
  }

  @POST('/posts')
  public createPost(@Body post: Post): Observable<Response> {
    return null;
  }

  @GET('/posts')
  @Produces<Post[]>(res => <Post[]>res.json())
  public getPosts(@Query('userId') userId?: number): Observable<Post[]> {
    return null;
  }
}

export class Post {

  constructor(
    public userId: number,
    public title: string,
    public body: string,
    public id?: number
  ) {}
}
// demo.component.ts
import {Component, Input} from '@angular/core';
import {DemoService, Post} from './demo.service';

@Component(...)
export class Demo {
  @Input() public demoPost: Post = new Post(1, 'Demo Title', 'Demo Body');
  @Input() public demoList: Post[] = [];

  constructor(public demoService: DemoService) {
    this.getPosts();
  }

  createPost() {
    this.demoService.createPost(this.demoPost);
  }

  getPosts() {
    this.demoService.getPosts().subscribe(res => {
      this.demoList = res;
    });
  }
}

Documentation

All documentation is auto-generated from the source via typedoc and can be viewed here: https://hboylan.github.io/ng2-rest/docs/

Development

Prepare your environment

  • Install Node.js and NPM (should come with)
  • Install local dev dependencies: npm install while current directory is this repo

Development server

Run npm start to start a development server on port 8000 with auto reload + tests.

Testing

Run npm test to run tests once or npm run test:watch to continually run tests.

Release

  • Bump the version in package.json (once the module hits 1.0 this will become automatic)
npm run release

License

MIT

Keywords

angular2

FAQs

Package last updated on 04 Nov 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts