Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RESTService transform function at a method level #179

Closed
emoralesb05 opened this issue Nov 30, 2016 · 1 comment
Closed

RESTService transform function at a method level #179

emoralesb05 opened this issue Nov 30, 2016 · 1 comment

Comments

@emoralesb05
Copy link
Contributor

emoralesb05 commented Nov 30, 2016

Feature Request

A way to override the transformation (transform) function provided at a service level.

What is the expected behavior?

Be able to return a parsed or diff object without affecting the other methods from any RESTService methods (query, get, etc etc).

e.g. Wanting to parse the response before returning it or returning response headers with the data.

Usage

Current:

public query(query?: IRestQuery): Observable<Array<T>> {
    let request: Observable<Response> = this.http.get(this.buildUrl(undefined, query), this.buildRequestOptions());
    return request.map<Array<T>>((res: Response) => {
      return <Array<T>>this.transform(res);
    }).catch<any>((error: Response) => {
      return new Observable<any>((subscriber: Subscriber<any>) => {
        try {
          subscriber.error(this.transform(error));
        } catch (err) {
          subscriber.error(error);
        }
      });
    });
  }

Desired (maybe):

public query(query?: IRestQuery, transform?: IRestTransform): Observable<Array<T>> {
    let request: Observable<Response> = this.http.get(this.buildUrl(undefined, query), this.buildRequestOptions());
    return request.map<Array<T>>((res: Response) => {
      if (transform) {
         return <any>transform(res);
      }
      return <Array<T>>this.transform(res);
    }).catch<any>((error: Response) => {
      return new Observable<any>((subscriber: Subscriber<any>) => {
        try {
          subscriber.error(this.transform(error));
        } catch (err) {
          subscriber.error(error);
        }
      });
    });
  }
@emoralesb05 emoralesb05 added this to the Alpha 0.10 milestone Dec 1, 2016
kyleledbetter pushed a commit that referenced this issue Dec 19, 2016
* adding an extra parameter for a transform callback in the rest methods

* added demo code placeholder for http tests

* Updated docs and readme

* added onRequestError interceptor

* updated docs and readme with onRequestError hook

* removed the CDATA from demo by mistake

* move text in docs to fit screen better

* added unit tests for RESTService with basic tests (normal cases)

* added use case with string parameter names (dashes)

* added unit test for baseHeader checkup

* added unit test for dynamicHeaders

* added tests for service transform and method transform

* fixed lint issues

* changed id-for-something to id-of-something for consistency

* removed DemoServices since unit tests are gonna be used for testing the RESTService
@emoralesb05
Copy link
Contributor Author

Added with #192

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant