What should be the RESTful API endpoint or URL signature for inserting bulk data using excel sheet

Viewed 210

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.
1 Answers

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

Related