RESTful API: which combination of METHOD / HEADER is used only for validation

I would like my API to have a request only for validation. For example, if I have a URL, for example:

http://api.somesite.com/users/12345 

and the user fills out a customer information form, which I will ultimately call PATCH / PUT / POST. When a user fills out a form, I can periodically send a partially updated view to it on the server so that I can display confirmation of their input in real time (for example, "This username has already been completed", "This password is too short").

There is no standard HTTP method or HEADER that seems to allow this behavior on the same resource. It seems my options are:

  • Create a new subordinate resource to verify
  • Use your own header (only for x-somesite-validation-only) and PUT indicating that I want to check but not save
+6
source share
2 answers

Some options

1) Using a custom header
2) Put something in the query line to confirm only 3) Use a URl action, for example. \ IndividualClient \ 123 \ actions \ Validate \ Invoke {section 19 here http://restfulobjects.files.wordpress.com/2011/11 /restful-objects-spec-052.pdf }
4) Hierarchical URL, for example. \ IndividualClient \ 123 \ Validation

From this post I find this tip

Use POST every time you need to do something with an RPC-like Do use GET for things like computing, if your input is large, in this case use POST

As for your specific question, POST should be used for # 4 and # 5. These operations fall> in accordance with the "RPC-like" guideline above. For # 5, remember that POST does not have to> use Content-Type: application / x-www-form-urlencoded. It could also just be a JSON or CSV payload.

Here is what I am considering:

This is a resource addition:
user / check
Post
Request: UserResource
Answer: ValidationResult
Response codes 200, 400. 404. 500

This is a resource update.
user / 204 / validation
Post
Request: UserResource,
Answer: ValidationResult Answer codes 200, 400. 404. 500

+2
source

A variant of Thrid is to implement a check function on the client. This function will then send a specific request when it needs specific information.

For example, you really do not need to send a request to check if the password is too short. But you can send one request to check if the username exists.

Here's how to test using Ajax, by the way, using the Restful API (HTTP) :)

0
source

Source: https://habr.com/ru/post/916051/


All Articles