【发布时间】:2017-12-29 17:29:28
【问题描述】:
我已经为我的应用程序实现了 RestAPI。现在我正在尝试使用 Angular 开发前端应用程序。每个 RestAPI 返回一个单独的 JSON 对象。除了为每个 http 请求实现对单个 RestAPI 的每次调用之外,有没有办法实现一个接口来很好地进行 RestAPI 调用?具体如下,
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));
这里有两种不同的方法,但是我可以通过传入 API URL 和类名来生成一个接口来包含这 3 个方法调用吗?
this.call_restapi(url, 'Person');
this.call_restapi(url, 'Animal');
this.call_restapi(url, 'Flower');
您能否就此提供一些想法?
【问题讨论】:
标签: angular interface endpoints