简体   繁体   English

如何形成ASP.NET OData WebApi的PATCH主体?

[英]How do I form the body of a PATCH for a ASP.NET OData WebApi?

I am new to PATCH|MERGE and want to know how to use it, client-side. 我是PATCH | MERGE的新手,想在客户端知道如何使用它。 I am not sure what to send in the body of the payload in JSON. 我不确定要在JSON中发送有效内容的内容。

Here is a contrived example POCO model in C# for discussion purposes. 这是出于讨论目的在C#中人为设计的示例POCO模型。

public class Person
{
  public Guid Id { get; set; }
  public string FullName { get; set; }
  public int Age { get; set; }
}

If you Google for an answer, you'll see various examples of JSON patch where the JSON payload describes one or more operations, such as this one which replaces/updates a value: 如果您用Google来寻找答案,则会看到JSON补丁的各种示例,其中JSON有效负载描述了一个或多个操作,例如该操作替换/更新了一个值:

PATCH /people/guid123lalala HTTP/1.1    
Content-Type: application/json-patch

{
  "op": "replace",
  "path": "/FullName",
  "value": "Willy Lopez"
}

Or this one: 或者这个:

PATCH /people/guid123lalala HTTP/1.1    
Content-Type: application/json-patch

[
  {"replace": "/FullName", "value": "Willy Lopez"}
]

(Which I'm not even sure is correct for JSON-patch.) (我什至不确定JSON修补程序是否正确。)

However, the application/json-patch format is not supported. 但是,不支持application/json-patch格式。 So as of January 2015, for OData on WebApi 2.2, just send the object with the non-changing properties omitted, like this using normal JSON: 因此,自2015年1月起,对于WebApi 2.2上的OData,只需发送具有不变属性的对象即可,就像使用普通JSON一样:

PATCH /people/guid123lalala HTTP/1.1    
Content-Type: application/json

{
  FullName: "Willy Lopez"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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