如何在 Azure 静态 Web 应用程序中处理 REST API 调用

问题描述 投票:0回答:1

我想创建一个 Gatsby Azure 静态 Web 应用程序。

通过 REST API 连接到不同 Azure 静态 Web 应用程序表单中的 Azure SQL 数据库来实施 CRUD 操作的最佳实践是什么?

请考虑两种不同类型的桌子:

  1. 1:1/1:N 关系表 -> 例如:Books-Table
  2. N:M 关系表 -> 例如:图书-类别-表

这是我的想法:

1:1/1:N 关系表

C(reate) book form: 
   POST (for inserting new book)
R(ead) book(s) form:
   GET (for selecting one or all books)
U(pdate) book form:
   PUT (for updating the selected book)
D(elete) book form:
   DELETE (for deleting the selected book)

N:M关系表

C(reate) book-category form: 
   POST (for inserting new book-category combinations)
R(ead) book-category form:
   GET (for selecting one or all book-category combinations)    
U(pdate) book-category form:
   DELETE (for deleting all book-category combinations)
   POST (for inserting the updated/new book-category combinations)
D(elete) book-category form:
   DELETE (for deleting the relevant book-category combination)

有没有其他函数可以专门处理N:M关系表的更新?

我可以发送任何请求来检查哪些图书类别组合已存在并正确处理它们吗?

我对不同的想法或方法完全持开放态度。

rest azure-sql-database azure-static-web-app
1个回答
0
投票

我的主要问题是:如何实现N:M关系的更新。 我有一个表书(以 book_id 作为主键)和一个表书类别(以代理键“书和类别”)

例如,图书类别表如下所示: 第 1 册 - 类别 10 第 1 册 - 第 11 类

现在我想通过表单和 REST API 调用更新相关类别。 第 1 册 - 类别 10 第 1 册 - 类别 20

我怎样才能做到这一点? 我是否必须删除“book = 1”的所有条目,然后插入新值? 我无法更新书籍,我必须更新书籍类别表。

© www.soinside.com 2019 - 2024. All rights reserved.