sab
sab

Reputation: 5042

define a response for a REST Api on a validation endpoint

I struggle to find the good way to respect the REST principle for an http endpoint:

I should define an endpoint who will check that a complex form object fill a few conditions and return the list of the unfilled conditions. (no change in the database will be produce by the endpoint ). Basically it's a validator

POST .../myComplexForm/validate-myvalidationCase

Request: myComplexForm{field1: int, field2:int ....}

Response : ??????

What is the proper way to define this response-bject respecting REST ?

The endpoint can find in the object more than one error and should return all of them, not just one ( It's not a validation field by field. More a "you are not allowed to have more than XXX if it's Sunday and you are YYYY)

What should the endpoint return?

Thanks !

Upvotes: 0

Views: 318

Answers (1)

Evert
Evert

Reputation: 99786

If the purpose of the endpoint is to receive any object, and return whether the object was valid or not, then in my opinion sending an invalid object is not really an error.

An error should tell a client, 'you should stop doing that', or 'you should change something about your request and try again', but in this case the explicit purpose is to also report invalid sates.

So if the object was invalid, I would still probably return a 200 OK. I don't really have an opinion on what format your result should be, as it depends on what the goal is of this feature. You should return what the client needs.

Upvotes: 1

Related Questions