Paldom / angular2-rest

Angular2 HTTP client to consume RESTful services. Built with TypeScript.
MIT License
248 stars 72 forks source link

Stuff #3

Closed Discountrobot closed 8 years ago

Discountrobot commented 8 years ago
chore(tslint) better collaboration effort

Added a tslint.json config file so that contributions can be uniform in style.

fix(pPath url scoped)

Fixed a bug i introduces..

feat(methodBuilder) added HEAD method

Added support for the HEAD method ( writing a swagger.io spec client generator, so i need to support these)

feat(@Produces) short-hand decorator for parsing responses

Adapted the JAX-RS notation, for specifying what response MIME type to expect, and then return the parsed result to the responseIntercepter.

import {... Produces, MediaType} from 'angular2-rest';

export class TodoRESTClient extends RESTClient {

    protected requestInterceptor(req: Request) {
     //
    }

    protected responseInterceptor(obs: Observable) {
        return obs.debounceTime(1000);
    }

    @GET("todo/")
    @Produces(MediaType.JSON)
    public getTodos( @Query("sort") sort?: string): Observable { return null; };
    // => returns JSON.parsed object

    @GET("todo/{id}")
    public getTodoById( @Path("id") id: string): Observable { return null; };
    // => returns a string

}

One could also argue that responses should be parsed by default, should 'Accept': 'application/json' be set, as the server should always respond with a parseable JSON string?

Paldom commented 8 years ago

Thanks @Discountrobot, awesome stuff!