[Answered ]-Choosing the right place to write logic in a client/api/server solution

2👍

PUT and POST are designed to be used to create and update resources. The server may or may not have a database behind it. It might use a local filesystem, or it might handle anything in memory. It’s none of the client’s business. It is certainly common to have business logic on most servers which provide APIs.

Use PUT/POST to send up the email address to the server. The server checks to see if the email address is (a) valid, and (b) allowed. If it fails either check, return a relevant response to the client as documented in the RFC. I would go with 403 Forbidden, which indicates a problem with the data being sent up to the server. Use the entity in the response to detail what the problem was with the request.

0👍

I had done similar thing in a angular web app,

I have disabled the submit button, and added a check availability button beside the email field.

I have send the email to server and checked if it already exist and got the result to client,
then asked the user to enter an alternate email if not valid or enable the form’s submit button

Alternatively

when the user leaves the email field, You can send the email to a service that validates the email, and get the response, and show a message that this email already exist and disable the submit, or enable the submit button otherwise

👤Vamsi

Leave a comment