2022/04/20 1 • Why we might want to update or retrieve only specific pieces of a resource ◦ 鄉民都只對特殊資訊感興趣 • How best to communicate the fields of interest to the API service ◦ 鄉民都只對自己有利的感興趣 • How to handle individual items in complex fields, such as maps and interfaces • Whether to support addressing individual items in a repeated field (e.g., arrays) • Defining default values and handling implicit field masks • How to deal with invalid field specifications
only specific pieces of a resource ◦ 鄉民都只對特殊資訊感興趣 • How best to communicate the fields of interest to the API service ◦ 鄉民都只對自己有利的感興趣 • How to handle individual items in complex fields, such as maps and interfaces • Whether to support addressing individual items in a repeated field (e.g., arrays) • Defining default values and handling implicit field masks • How to deal with invalid field specifications
=> PATCH 8.2 Overview - Goals 9 a field mask is just a collection of strings, but these strings represent a list of fields that we’re interested in on a given resource.
request permitted (and many HTTP servers will strip it out if one is provided) 2. PATCH: resource-oriented design dictates that the body of a PATCH request must be the resource representation being updated two potential places: 1. headers 2. query strings: how the repeated query string parameters are interpreted will depend on the HTTP server in use 14
nested structures? Or does it only apply at the very top level, effectively treating resources as completely flat structures? 8.3.2 Maps and nested interface 19
dot character (.) as a separator. 2. All fields of a nested message may be referred to using an asterisk character (*). 3. Map keys should always be strings. 4. All parts of a field specification that can’t be represented as an unquoted string literal must be quoted using backtick characters (`). 5. A literal backtick character may be escaped by using two backtick characters (``) Rules for field mask to specify nested fields. 21
to do “the right thing” for the user. GET: standard get method, the default is almost always the complete list of fields available on a resource. 標準 GET 會取得所有的 Fields There is an exception to this guideline. In cases where a resource has fields which, for whatever reason, would cause a fundamentally worse user experience for API consumers, these fields should be removed from the default of the field mask being left unset. 如果有一些 Fields 會導致 API 使用者的使用體驗不好,這些 fields 應該從 field mask 的預設中 被移除 使用者有興趣的時候,自行透過 fieldMask 指定 Fields 取得。 25
update method (using an HTTP PATCH method)? Most commonly, HTTP PATCH indicates an intent to update the resource with only the data provided in the body of the request. 8.3.5 Implicit field masks 33
unnecessary data transfer and b. allow fine-grained modification of API resources. • consider field masks and partial retrievals in particular as SQL-like querying tools to fetch specific data 8.4 Trade-offs 41
are large or clients consuming resource data have limited hardware. => POS 2. Partial updates are critical for fine-grained updates without worrying about conflicts. 3. Field masks, which support ways to address fields, nested fields in interfaces, and map keys, should be used to indicate the fields that should be retrieved or updated. 4. Field masks should NOT provide a mechanism to address items in array fields by their position or index in that field. 5. By default, field masks should assume a value of everything for partial retrievals and an implicit field mask (8.3.5) for partial updates. 6. If fields are invalid, they should be treated as though they do exist but have a value of undefined. Summary 47