使用 Excel 工作表插入批量数据的 RESTful API 端点或 URL 签名应该是什么

发布于 2025-01-16 00:13:20 字数 1121 浏览 0 评论 0原文

情况1:我需要使用excel(xls)插入批量用户。

我实现的内容:

URL: [POST] {{base_url}}/users/bulk
Content: Form Data-MultiPart

Request Body:
fileName: users_20Jan
file: /home/desktop/users.xls

Response Code: 201

该API执行的操作:

  1. 将导入users.xls文件保存到云端并输入数据库。
  2. 阅读 Excel 工作表的每一行。检查是否存在具有相同凭据的用户。
  3. 将数据设置为对象并保存到数据库。

情况2:我需要使用excel(xls)插入批量用户,但excel文件已经存在于云端。

我实现的内容:

URL: [POST] {{base_url}}/users/bulk/{{import_file_id}}

Request Body: Empty

Response Code: 201

此 API 执行的操作:

  1. 使用 importFileId 从数据库获取文件的下载 URL。
  2. 从云端下载文件。
  3. 阅读 Excel 工作表的每一行。检查是否存在具有相同凭据的用户。
  4. 将数据设置为对象并保存到数据库。

是否为这些类型的 RestAPI 定义了任何标准化?如果没有那么有更好的方法吗?


仅供参考

 URL: `{{base_url}}/users` is already being used for single-user and an array of users in the JSON request body.

 These all are requirements of the project.

Case 1: I need to insert bulk users using excel(xls).

What I implemented:

URL: [POST] {{base_url}}/users/bulk
Content: Form Data-MultiPart

Request Body:
fileName: users_20Jan
file: /home/desktop/users.xls

Response Code: 201

Operations performed by this API:

  1. Save import users.xls file to cloud and make entry into the database.
  2. Read each row of the excel sheet. Check users with the same credentials already exist.
  3. Set data to object and save to database.

Case 2: I need to insert bulk users using excel(xls) but the excel file is already present on the cloud.

What I implemented:

URL: [POST] {{base_url}}/users/bulk/{{import_file_id}}

Request Body: Empty

Response Code: 201

Operations performed by this API:

  1. Get a download URL for the file using importFileId from the database.
  2. Download file from the cloud.
  3. Read each row of the excel sheet. Check users with the same credentials already exist.
  4. Set data to object and save to database.

Is there any standardization defined for these types of RestAPI. If not then is there any better way of doing this?


FYI

 URL: `{{base_url}}/users` is already being used for single-user and an array of users in the JSON request body.

 These all are requirements of the project.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

战皆罪 2025-01-23 00:13:20

只需添加 requestparam 类型即可将 url 合并为一个。

示例:

  {{base_url}}/users/files/{{filename}}?type=file
  {{base_url}}/users/files/{{import_file_id}}?type=fileId

这样我们就可以重复使用相同的方法来进行类似的操作

You can combine url into one by just adding type requestparam.

example:

  {{base_url}}/users/files/{{filename}}?type=file
  {{base_url}}/users/files/{{import_file_id}}?type=fileId

In this way we can reuse same method for similar operation

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文