Native name and http method for REST endpoint to validate JSON

I want to implement a REST endpoint that is designed to validate a complex entity in JSON format.

So the first question is which HTTP method should you use? We cannot put JSON in the body for the GET method. POST and PUT are methods to be used when some changes are made to the DB, but validation does not make any changes.

And the second question is, what resource name might be appropriate for such an endpoint?

+3


source to share


2 answers


The main difference between POST and PUT is that PUT is idempotent, while POST is not.

So the question is, if you use the same validation query twice, would you expect a different result? I think not, so PUT is probably the best choice.

I want to be efficient RESTful, one of the constraints is that the endpoint has to target the resource you want to deal with, the HTTP method that specifies what you want to do with it. So in your case, I would personally choose:

PUT /api/v42/validation

      



As @RomanVottner suggested, you can also solve this problem by treating each request as a "new validation report message", in which case POST would be more appropriate:

POST /api/v42/validations

      

Anyway, you are running into one of these red cases where REST needs to be tweaked a little, as this need is outside of the CRUD world.

+2


source


My general rule of thumb is when you need the full JSON body go with POST.

You have a post method like / validateJSON or whatever, GET doesn't work, PUT doesn't make sense, so continue with POST.



Refer to: What REST operation (GET, PUT or POST) to validate information?

Greetings.

0


source







All Articles