angular - 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:
- What is the best way to handle the sending of parameters in Angular to an API (basic approach)?
- What is the best structure to have?
- A model for each call, even if it has common attributes?
- Is possible to have a generic model, and popule only few attributes for each API call?
解决方案
作为 Angular 框架一部分的 HTTPClient 应该有你需要的东西。它还有一个 HttpParams 类,您可以使用它来设置参数,并在需要时创建可重用的参数逻辑。
这将是 Angular 团队构建的最标准/基本的方法。
推荐阅读
- javascript - v-toggle 的自定义按钮激活
- mongodb - mongodb管道聚合组结果成数组
- git - 如何将 GitLab FOSS 从 12.7.5 升级到 12.8.5(综合包)?
- c# - 我在 C# 中创建家谱时遇到了麻烦
- arm - 检测 Thumb-2 指令和 PC 偏移的位置
- matlab - 找到线性系统精确解的最快方法是什么,matlab
- c# - 为什么此 LINQ 表达式返回只有一项的子列表
- redux - Immutable.js:创建一个包含一个元素的列表
- javascript - 触发 Modal 以在 useEffect 挂钩内显示的问题
- javascript - AWS Lambda 函数:无法读取未定义的属性 'logs' 'numberOfPages' 'stream'。包问题或 AWS Lambda 问题?