C
C#13mo ago
_vegabyte_

✅ Proper implementation of API

Hi guys, so I have a client registration implementation. The client should input their Personal Information, Terms and Conditions, and add some valid documents. I divided them to 3 APIs, AddPersonalInfo, AddTermsAndCondition, AddAttachments. Since the informations is needed to provide all at once it means I will calling the API one by one, one after another. Do you guys think it's good practice? Or is there any another approach for this implementation. My concern is what if one of the API is failed, the saving should not be completed and be voided. Your suggestion are well appreciated. Thanks
6 Replies
Angius
Angius13mo ago
Why is it three different calls, exactly...? I'd think it can all be one form, and one payload Or, at least, user info + ToC acceptance should be one thing Then you have a complete user, that can have an "invalid" state Then, when they upload valid documents, the state changes to "valid"
_vegabyte_
_vegabyte_OP13mo ago
My primary reason is Personal info and ToC for me is different. So i decided to create different APIs. Yeah, since I'm already saving sa personal info and Terms, is there any good approach like when the user is in the Uploading section and canceled the registration it will delete the Personal Infos and ToC? Because the primary reason for this is the Information is already on the database and if the user try to add the same info again it will be getting some validation errors.
Angius
Angius13mo ago
You can detect the user clicking some "cancel" button, but not so much if the user closes the tab or the browser Your best bet would be a timer If no valid documents are uploaded within 5/10/15/whatever minutes, delete the data
_vegabyte_
_vegabyte_OP13mo ago
Ohh yeah, maybe I will check the database for the clients that has no document yet within that time frame it will delete the data related to that client. What do you think?
Angius
Angius13mo ago
Yep Some sort of a CRON job that runs every now and then, checks the user creation date, and if it's older than X minutes and the user has status "invalid", delete the data
_vegabyte_
_vegabyte_OP13mo ago
Okay, It is now clear to me how to adjust my API, I'll try to merge AddPersonalInfo and ToC. Thank you very much!!!
Want results from more Discord servers?
Add your server