ng2-rest
Last updated a month ago by darekf77 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ng2-rest 
SYNC missed versions from official npm registry.

ng2-rest

Isomorphic REST framework for Browser and NodeJS apps.

Simple, robust, efficient REST api for typescript frameworks like: Angular, React, ExpressJS and others.

Nice way to:

  • connect your webapp with RESTfull backend or JSONP api
  • access from NodeJS server third part APIs ( in the same way as in the browser)

Plunker demo

To install package run:

npm install ng2-rest --save

Import Resource class:

import { Resource } from 'ng2-rest';

Resource

Fit you existing API (not only REST) into new fluent objects with Resource class observables. Use power of async in new angular templates;

template.html

Users:
<ul   *ngIf="model.allUsers() | async; else loader; let users" >

  <li  *ngFor="let user of users"> 
  		{{user.id}} {{user.fullName()}} 
		  <br>
		<input type="name" [(NgModel)]="user.name" >
		<button (click)="model.update(user)" > Update </button>
  </li>

</ul>

<ng-template #loader> loading users...  </ng-template>

component.ts

class User {
	name: string;
	surname: string;
	id: number;

	fullName() {
		return `Surname: ${this.surname}, Name: ${this.name}`;
	}
}

// Express.js style url endpoint model
// you can ommit "<User>" part is you don't wanna see response interface
// also you can ommit third argument ",User" is you don't wanna
// map response object to User class objects
const rest = Resource.create<User>("http://yourbackend.com/api","users/:id",{'':User} )

class UserComponent {

   // Prepare your beautiful interface
    model = {
	 allUsers: () => rest.model()
		 .array
		 .get()
		 .observable // Observable resposne (useful for Angular 2+ html templates)
		 .map({ body } => body.json)  , // get all users, body.json => User[] 

	 userBy: (id) => rest.model({id})
		 .get() // Promise response by default
		 .then({ body } => console.log(body.json)) // get user by id,  body.json => User

	 update: async (user:User) =>{
		 try {
			await rest.model({id:user.id}).put(user) // Promise response by default

			alert('Update sucess')
		 } catch(e) {
			alert(e)
		 }	
	 	}
    }

	constructor() { }

}

Specification

Example UrlParams[] : [ { sort: true },{ filter: 'id,5' }, { filter: 'name,test' } ]

Name Parameters Description
.array. get,post,put,delete,jsonp for everything, but with arrays
get UrlParams[] get model by parameters
post model, UrlParams[] post object model
put model, UrlParams[] put object model
delete UrlParams[] remove object by params
jsonp UrlParams[] get jsonp data

Production mode

Nice things to do in production mode:

1. Disable warnings.

If you don't wanna see warning, disable it like this:

if (environment.production) {
  Resource.enableWarnings = false;
}

Angular AOT

If you are using Angular 2+ and AOT ( Ahead Of Time Compilation ), you need to do this in your app.component:

constructor(zone:NgZone) {
    Resource.initAngularNgZone(zone)
}

Current Tags

  • 9.2.26                                ...           latest (a month ago)

226 Versions

  • 9.2.26                                ...           a month ago
  • 9.2.20                                ...           3 months ago
  • 9.2.19                                ...           3 months ago
  • 9.2.18                                ...           3 months ago
  • 9.2.17                                ...           3 months ago
  • 9.2.16                                ...           3 months ago
  • 9.2.15                                ...           5 months ago
  • 9.2.14                                ...           5 months ago
  • 9.2.13                                ...           5 months ago
  • 9.2.12                                ...           6 months ago
  • 9.2.11                                ...           7 months ago
  • 9.2.10                                ...           7 months ago
  • 9.2.9                                ...           8 months ago
  • 9.2.8                                ...           8 months ago
  • 9.2.6                                ...           8 months ago
  • 9.2.5                                ...           8 months ago
  • 9.2.2                                ...           8 months ago
  • 9.2.1                                ...           8 months ago
  • 9.1.19                                ...           8 months ago
  • 9.1.18                                ...           8 months ago
  • 9.1.17                                ...           9 months ago
  • 9.1.16                                ...           9 months ago
  • 9.1.15                                ...           9 months ago
  • 9.1.14                                ...           9 months ago
  • 9.1.13                                ...           10 months ago
  • 9.1.12                                ...           a year ago
  • 9.1.11                                ...           a year ago
  • 9.1.10                                ...           a year ago
  • 9.1.9                                ...           a year ago
  • 9.1.8                                ...           a year ago
  • 9.1.7                                ...           a year ago
  • 9.1.6                                ...           a year ago
  • 9.1.5                                ...           a year ago
  • 9.1.4                                ...           a year ago
  • 9.1.3                                ...           a year ago
  • 9.1.2                                ...           a year ago
  • 9.1.1                                ...           a year ago
  • 9.0.11                                ...           a year ago
  • 9.0.10                                ...           2 years ago
  • 9.0.9                                ...           2 years ago
  • 9.0.8                                ...           2 years ago
  • 9.0.7                                ...           2 years ago
  • 9.0.6                                ...           2 years ago
  • 9.0.5                                ...           2 years ago
  • 9.0.4                                ...           2 years ago
  • 9.0.3                                ...           2 years ago
  • 9.0.1                                ...           2 years ago
  • 8.0.4                                ...           2 years ago
  • 8.0.3                                ...           2 years ago
  • 8.0.2                                ...           2 years ago
  • 8.0.1                                ...           2 years ago
  • 7.2.4                                ...           2 years ago
  • 7.2.3                                ...           2 years ago
  • 7.2.2                                ...           2 years ago
  • 7.2.1                                ...           2 years ago
  • 7.1.10                                ...           2 years ago
  • 7.1.9                                ...           2 years ago
  • 7.1.8                                ...           2 years ago
  • 7.1.5                                ...           2 years ago
  • 7.1.4                                ...           2 years ago
  • 7.1.3                                ...           2 years ago
  • 7.1.2                                ...           2 years ago
  • 7.1.1                                ...           2 years ago
  • 7.0.17                                ...           2 years ago
  • 7.0.16                                ...           2 years ago
  • 7.0.15                                ...           2 years ago
  • 7.0.10                                ...           2 years ago
  • 7.0.9                                ...           2 years ago
  • 7.0.8                                ...           2 years ago
  • 7.0.4                                ...           2 years ago
  • 7.0.3                                ...           2 years ago
  • 7.0.2                                ...           2 years ago
  • 6.1.3                                ...           2 years ago
  • 6.0.14                                ...           2 years ago
  • 6.0.13                                ...           2 years ago
  • 6.0.12                                ...           2 years ago
  • 6.0.11                                ...           2 years ago
  • 6.0.10                                ...           2 years ago
  • 6.0.9                                ...           2 years ago
  • 6.0.8                                ...           2 years ago
  • 6.0.7                                ...           2 years ago
  • 6.0.6                                ...           2 years ago
  • 6.0.5                                ...           2 years ago
  • 6.0.4                                ...           2 years ago
  • 6.0.2                                ...           2 years ago
  • 6.0.1                                ...           2 years ago
  • 5.0.47                                ...           2 years ago
  • 5.0.46                                ...           2 years ago
  • 5.0.44                                ...           3 years ago
  • 5.0.43                                ...           3 years ago
  • 5.0.42                                ...           3 years ago
  • 5.0.41                                ...           3 years ago
  • 5.0.40                                ...           3 years ago
  • 5.0.38                                ...           3 years ago
  • 5.0.37                                ...           3 years ago
  • 5.0.36                                ...           3 years ago
  • 5.0.35                                ...           3 years ago
  • 5.0.34                                ...           3 years ago
  • 5.0.33                                ...           3 years ago
  • 5.0.32                                ...           3 years ago
  • 5.0.31                                ...           3 years ago
  • 5.0.30                                ...           3 years ago
  • 5.0.28                                ...           3 years ago
  • 5.0.27                                ...           3 years ago
  • 5.0.26                                ...           3 years ago
  • 5.0.24                                ...           3 years ago
  • 5.0.22                                ...           3 years ago
  • 5.0.20                                ...           3 years ago
  • 5.0.19                                ...           3 years ago
  • 5.0.18                                ...           3 years ago
  • 5.0.15                                ...           3 years ago
  • 5.0.14                                ...           3 years ago
  • 5.0.13                                ...           3 years ago
  • 5.0.11                                ...           3 years ago
  • 5.0.9                                ...           3 years ago
  • 5.0.8                                ...           3 years ago
  • 5.0.7                                ...           3 years ago
  • 5.0.6                                ...           3 years ago
  • 5.0.5                                ...           3 years ago
  • 5.0.4                                ...           3 years ago
  • 5.0.3                                ...           3 years ago
  • 5.0.1                                ...           3 years ago
  • 4.1.47                                ...           3 years ago
  • 4.1.45                                ...           3 years ago
  • 4.1.44                                ...           3 years ago
  • 4.1.43                                ...           3 years ago
  • 4.1.42                                ...           3 years ago
  • 4.1.41                                ...           3 years ago
  • 4.1.40                                ...           3 years ago
  • 4.1.38                                ...           3 years ago
  • 4.1.37                                ...           3 years ago
  • 4.1.35                                ...           3 years ago
  • 4.1.33                                ...           3 years ago
  • 4.1.32                                ...           3 years ago
  • 4.1.31                                ...           3 years ago
  • 4.1.30                                ...           3 years ago
  • 4.1.29                                ...           3 years ago
  • 4.1.28                                ...           3 years ago
  • 4.1.25                                ...           3 years ago
  • 4.1.24                                ...           3 years ago
  • 4.1.23                                ...           3 years ago
  • 4.1.22                                ...           3 years ago
  • 4.1.20                                ...           3 years ago
  • 4.1.19                                ...           3 years ago
  • 4.1.17                                ...           3 years ago
  • 4.1.16                                ...           3 years ago
  • 4.1.15                                ...           3 years ago
  • 4.1.13                                ...           3 years ago
  • 4.1.12                                ...           3 years ago
  • 4.1.11                                ...           3 years ago
  • 4.1.10                                ...           3 years ago
  • 4.1.9                                ...           3 years ago
  • 4.1.7                                ...           3 years ago
  • 4.1.4                                ...           3 years ago
  • 4.1.3                                ...           3 years ago
  • 4.1.2                                ...           3 years ago
  • 4.1.1                                ...           3 years ago
  • 3.0.49                                ...           3 years ago
  • 3.0.48                                ...           3 years ago
  • 3.0.47                                ...           3 years ago
  • 3.0.46                                ...           3 years ago
  • 3.0.45                                ...           3 years ago
  • 3.0.44                                ...           3 years ago
  • 3.0.43                                ...           3 years ago
  • 3.0.42                                ...           3 years ago
  • 3.0.41                                ...           3 years ago
  • 3.0.40                                ...           3 years ago
  • 3.0.39                                ...           3 years ago
  • 3.0.38                                ...           3 years ago
  • 3.0.37                                ...           3 years ago
  • 3.0.32                                ...           3 years ago
  • 3.0.29                                ...           3 years ago
  • 3.0.27                                ...           3 years ago
  • 3.0.26                                ...           3 years ago
  • 3.0.24                                ...           3 years ago
  • 3.0.23                                ...           3 years ago
  • 3.0.22                                ...           3 years ago
  • 3.0.19                                ...           3 years ago
  • 3.0.18                                ...           3 years ago
  • 3.0.15                                ...           3 years ago
  • 3.0.13                                ...           3 years ago
  • 3.0.12                                ...           3 years ago
  • 3.0.11                                ...           3 years ago
  • 3.0.10                                ...           3 years ago
  • 3.0.9                                ...           3 years ago
  • 3.0.8                                ...           3 years ago
  • 3.0.7                                ...           3 years ago
  • 3.0.6                                ...           3 years ago
  • 3.0.5                                ...           3 years ago
  • 3.0.4                                ...           3 years ago
  • 3.0.3                                ...           3 years ago
  • 3.0.2                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           3 years ago
  • 1.0.33                                ...           3 years ago
  • 1.0.32                                ...           3 years ago
  • 1.0.31                                ...           3 years ago
  • 1.0.30                                ...           3 years ago
  • 1.0.29                                ...           3 years ago
  • 1.0.27                                ...           3 years ago
  • 1.0.26                                ...           3 years ago
  • 1.0.25                                ...           3 years ago
  • 1.0.23                                ...           3 years ago
  • 1.0.22                                ...           3 years ago
  • 1.0.21                                ...           3 years ago
  • 1.0.20                                ...           3 years ago
  • 1.0.19                                ...           3 years ago
  • 1.0.18                                ...           3 years ago
  • 1.0.17                                ...           3 years ago
  • 1.0.16                                ...           3 years ago
  • 1.0.15                                ...           3 years ago
  • 1.0.14                                ...           3 years ago
  • 1.0.13                                ...           3 years ago
  • 1.0.12                                ...           3 years ago
  • 1.0.11                                ...           3 years ago
  • 1.0.10                                ...           3 years ago
  • 1.0.9                                ...           3 years ago
  • 1.0.8                                ...           3 years ago
  • 1.0.7                                ...           3 years ago
  • 1.0.6                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 227
Last Day 0
Last Week 226
Last Month 20
Dependencies (11)

Copyright 2014 - 2016 © taobao.org |