ng-restly
v2.0.4
Published
Resource (REST) Service for Angular (2+)
Downloads
10
Maintainers
Readme
ng-restly
Resource (REST) service for Angular 2+.
Did you miss the ngResource service from angular1.x in angular2+? Then you have come to the right place.
Installation
npm install --save ng-restly
How To
- Create a service and extend it from ResourceService
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { ResourceService } from 'ng-restly';
@Injectable()
export class PostService extends ResourceService {
constructor(protected http: HttpClient) {
this.url = 'http://api.example.com/posts/:id';
super(http);
}
}
- Inject your service wherever you would like to take the benefits of ng-restly
import { PostService } from './post.service';
export class PostComponent implements OnInit {
constructor(private postService: PostService) {}
post: any; // Best Practice: Create and use an Interface as type (ie: PostInterface)
ngOnInit() {
this.postService
.get({ id: 123 })
.subscribe(post => this.post = post);
}
}
Documentation
See full documentation here.
Deprecated @angular/http module Support
ng-restly v1.0.0 supports the deprecated and soon to be removed @angular/http module. If you are using version below 4.4.0 of angular you have to install v1.0.0 of ng-restly.
npm install --save [email protected]
See full documentation for v1.0.0 here.
Development & Contribution
Run npm run test
to execute the unit tests via Karma. This will help you to run and debug your code if you wish to contribute to the development of this library.
Enjoy 😃