I have completed implementing RestAPI for my application. Now I am trying to develop front-end app with Angular. Each RestAPI returns an individual JSON object. Rather than implementing each call to individual RestAPI for each http request, is there any way to implement one single interface to make RestAPI calls nicely? Specifically, in the following,
this.http.get('http://a.b.c/api/people/1').subscribe(json => makePerson(json));
this.http.get('http://a.b.c/api/animal/1').subscribe(json => makeAnimal(json));
this.http.get('http://a.b.c/api/flower/1').subscribe(json => makeFlower(json));
There are two different methods here, but can I generate one interface to embrace those 3 method calls by passing in API URL and class name?
this.call_restapi(url, 'Person');
this.call_restapi(url, 'Animal');
this.call_restapi(url, 'Flower');
Could you please give some idea about this?
You could add a switch statement in your subscriber, and use an argument to navigate the GET request and switch statement.