What Result Type For Endpoint That Does Validation
I have an api endpoint that validates a number. It calls a helper method
ValidateTaxNumber(request)
, and it that is true, the endpoint returns a 200:
The Ok
function is ours, in our base controller and this set up result creation functions does not cater for all possible REST response?
I'm wondering what to return if the number isn't valid? The call was still a success, so I have half a mind to return the same result, but with result = true, response_object = true
. What other return options do I have? NotFound?10 Replies
The request is basically "is this valid?" so I'd say it makes sense to return 200 OK whether the answer is
yes
or no
That's what I thought, thanks, was just checking if there may have been some edge case response I wasn't aware of.
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
It's not a problem if "no" is a valid response though, is it?
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
It's basically equal to "does user exist" or "are there any items in the queue" requests
Ah
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
Yeah, you're right
Unknown User•2w ago
Message Not Public
Sign In & Join Server To View
I have to use the very limited set of result building functions in the base controller. These are all of Ok, BadRequest, NotFound, Unauthorized, Forbid, and InternalServerError. The payload is also a convention that I shouldn't deviate from in the legacy branches. We're not far off some sort of rewrite, and then I can suggest and explain all kinds of good and proper ways of doing these things.
I've settled on OK, because my endpoint calls an external, 3rd party endpoint, and whether or not that tax number is valid isn't as relevant as the fact that the call to the external api succeeded with a 200 response.