sweet suman
sweet suman

Reputation: 1082

Validator endpoint design

I have an endpoint that receives a registration form body to validate in the backend:

POST .../api/v1/validate-user

Then endpoint will response something like this:

200 OK

{
  "valid": false,
  "message": "The registration cannot continue."
}

The validation is done in the backend because it uses sensitive data in the server to validate the user. This process cannot be included in the actual "save" endpoint and properly accept/reject the request because of reasons I have no control of.

My question is: Is this a poor design because the endpoint responds 200 OK even if the validation does not yield a "good" or "positive" result?

... or is this OK because the server understood and processed the request properly and responded accordingly?

Upvotes: 1

Views: 311

Answers (1)

Eric Stein
Eric Stein

Reputation: 13682

That's perfectly fine. Conceptually, you're requesting a resource that tells you if the user is valid or not. You're getting a response that tells you if the user is valid or not. So your request went through just fine, and so a 200-level response is appropriate.

Upvotes: 1

Related Questions