2

I am using app-engine on the backend, with Google Cloud Endpoints to expose APIs for the front end. The Front end is using Angular2.

I have followed the strategy described here for javascript (or here for Angular1), and this pretty much works but does not blends in well with Angular2 at the moment as it is not Observable based, not wrapped in a service etc.

On DefinitelyTyped, I found these type definitions for Google Sign-In API but is only for authentication.

If no better strategy is identified, I'll end up writing a wrapper service for Gapi, but maybe someone has a better approach?

Julien
  • 3,613
  • 2
  • 23
  • 25
  • Possible duplicate of [Using http rest apis with angular 2](http://stackoverflow.com/questions/34755350/using-http-rest-apis-with-angular-2) – Brent Washburne May 03 '16 at 16:49
  • Brent, the question you linked is about Http. My question is about Google Cloud Endpoint specifically. – Julien May 03 '16 at 17:32
  • My mistake, I thought it was about Angular2. I have retracted the close vote. I would recommend that you add a little more detail about a specific question instead of the broad question of a better approach. – Brent Washburne May 03 '16 at 20:03
  • Any updates on this particular project? Was a wrapper-service ultimately what you went with? – yoonjesung Oct 02 '17 at 14:58

1 Answers1

0

How about you use Promise?

maybe.service.ts

function getPerson:  Promise<FooBarResponse>(){
  var arg:ArgFooBarPeople = new ArgFooBarPeople();
  return new Promise<FooBarResponse>(
            (resolve,reject) =>
            { gapi.client["foobarapi"]["person"].all(arg).execute(
                    (response:any)=>{
                        resolve(response);
                    });
            }
        );
}

maybe.component.ts

function load(){
    this._foobarService.getPerson()then(
             (response:FooBarResponse):void =>{
                    console.log(response);
                    this.fooBarResponse = response;
        }).catch( (error)=>{this.error="error !!"});
}