In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article is to share with you about WebApiClient JsonPatch partial update is how, the editor feels very practical, so share with you to learn, I hope you can learn something after reading this article, say no more, follow the editor to have a look.
1. Purpose of the article
With the continuous improvement of WebApiClient, more and more developers choose WebApiClient to replace the native HttpClient. The new features of using WebApiClient to complete JsonPatch submission are described below.
2. Json patch introduction
During server WebApi development, if an interface is designed to update the login user's personal information, the user can update multiple fields such as nickname, password, birthday, gender, etc., but in actual use, the user may update one or more of the fields. Developers are often in a dilemma: what value should be set for fields that have not been updated by the client? One is to let the client synchronize from the server and then update the relevant fields. The other is that the fields that are not updated are set to null, and the fields received by the server are not updated, but this is still ambiguous (in the case of updating to null).
Json patch is a standard interaction designed for the client to locally update the existing resources on the server. Json patch is introduced in detail in RFC6902. Generally speaking, there are the following main points:
Use the HTTP PATCH request method
Request body to describe the data json content of multiple opration
The requested Content-Type is application/json-patch+json
The following is a packet requested by json patch:
Op means operation and can be divided into the following categories:
Add add: {"op": "add", "path": "/ xxx", "value": "xxx"}, if the attribute does not exist, add the attribute, and if the attribute exists, change the value of the attribute.
Remove delete: {"op": "remove", "path": "/ xxx"}, delete an attribute, or set it to the default value (for example, a null value).
Replace replacement: {"op": "replace", "path": "/ xxx", "value": "xxx"}, changing the value of the attribute can also be understood as deleting and then adding.
Copy copy: {"op": "copy", "from": "/ xxx", "path": "/ yyy"}, assigning the value of an attribute to the target attribute.
Remove Mobile: {"op": "move", "from": "/ xxx", "path": "/ yyy"}, assign the value of the source attribute to the target attribute, and delete or set the source attribute to the default value.
Test test: {"op": "test", "path": "/ xxx", "value": "xxx"}, the value of the test target property is the same as the specified value.
4. Asp.net mvc receives JsonPatch
In Asp.net mvc, you can use the JsonPatchDocument type to process json patch content, and JsonPatchDocument can apply the action behavior to the target instance to get the data content after the operation.
5. WebApiClient submits JsonPatch
A JsonPatchDocument type is also provided in WebApiClient, which implements the IApiParameterable interface. After the http request, the BeforeRequestAsync method is executed to complete the assembly of the data json content of multiple opration of body.
The above is what the JsonPatch partial update of WebApiClient is like. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.