简体   繁体   中英

PATCH Request using the play framework (java)

I have been looking for a good way to implement a PATCH request using the Play Framework (2.2 Java) but have not been able to find a good way to accomplish this. Using a PUT request works great since validations can be ran through a form builder since all of the fields are sent, but since PATCH does not require all fields a form builder can not be used (to my knowledge). I was wondering what the best method of implementing a PATCH request with validations is?

For context, the request is in JSON not from a web form. If there is anything else I can include please let me know, thanks in advance!

I've not done this with Play specifically, but for other frameworks that don't support PATCH natively, I've implemented the PATCH semantics myself using a POST as the verb.

Essentially, the way I do it is to treat the POSTed data as updates to the resource. Then, after the new data is bound to the existing resource, the new version gets passed through the validation.

As long as you focus on PATCH as a "partial update", and default any fields not present in the request, you shouldn't have too much trouble implementing PATCH semantics, since just about every framework supports the concept of "Update" (from CRUD). In this case, you are just taking over the data binding by defaulting missing fields.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM