首页 > 解决方案 > What is the best way to send calls in Angular to an API?

问题描述

I have a system made in Angular that will perform several many CRUD operations on an API. There are many different calls in this API: GET, PUT and POST, in other words, many create, update and delete.

Some DELETE, for example, have similar attributes (code), but one has an attribute which other haven't (name, for example).

My questions:

  1. What is the best way to handle the sending of parameters in Angular to an API (basic approach)?
  2. What is the best structure to have?
  3. A model for each call, even if it has common attributes?
  4. Is possible to have a generic model, and popule only few attributes for each API call?

标签: angulartypescriptapicrud

解决方案


作为 Angular 框架一部分的 HTTPClient 应该有你需要的东西。它还有一个 HttpParams 类,您可以使用它来设置参数,并在需要时创建可重用的参数逻辑。

这将是 Angular 团队构建的最标准/基本的方法。

https://angular.io/guide/http


推荐阅读