Closed Discountrobot closed 8 years ago
Here is an update that mostly replaces/adds ng2 interfaces.
Note: This commit is meant as a discussion on how the component should align with the built-in interfaces
import {RESTClient, GET, PUT, POST, DELETE, BaseUrl, Headers, DefaultHeaders, Path, Body, Query} from './angular-rest' import {Injectable, Inject} from 'angular2/angular2' import {Observable} from 'angular2/core' import {Http, Request, Response} from 'angular2/Http' import {IFilter} from './loopback-interfaces' @Injectable() @BaseUrl("http://localhost:3000/api") @DefaultHeaders({ 'Accept': 'application/json', 'Content-Type': 'application/json' }) export class TodoRESTClient extends RESTClient { constructor( @Inject(Http) protected http: Http) { super(http) } protected requestInterceptor(req: Request) { req.headers.set('hello', 'world') } protected responseInterceptor(res: Response) { return res.json() } @GET("/") public find( @Query("filter") filter?: IFilter): Observable { return null } @GET("/{id}") public findById( @Path("id") id: string): Observable { return null } @DELETE("/{id}") public deleteById( @Path("id") id: string): Observable { return null } @GET("/{id}/exists") public exists( @Path("id") id: string): Observable { return null } @POST("/") public create( @Body data: any): Observable { return null; }; }
Thanks mate, this is awesome! :+1:
In the example, I'd rather use typed Observables, but its up to the user :)
Here is an update that mostly replaces/adds ng2 interfaces.
Note: This commit is meant as a discussion on how the component should align with the built-in interfaces
Additionally this commit:
Next up:
Example