An experimental study in using natural admixture as an alternative for chemic...
Chapter 8. Partial updates and retrievals.pdf
1. Part 3 Fundamentals
8. Partial Updates and Retrievals
Rick Hwang
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
2. 2
● 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
7. 7
1. Resource 新增
description field,也提供
新的 client
2. 舊的 client 持續在使用
=> 想像是 HTTP Client
or SDK 那種
3. 沒有考慮 back
compatible 就會出現
data loss
1
2
3
8. 1. 循序性的寫入,需要一致性檢查 (consistency checks)、或者 locking
2. versioning and compatiablity, see chatper 24
a. support new features
b. fix bugs
c. to add new fields to resources while still considering the new version backward compatible
核心問題
8
9. 1. Enabling partial retrievals => GET
2. Enabling partial updates => 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.
13. 8.3 Implementation
How we transport the field mask without causing any significant
disruption to the standard requests that defined in chapter 7.
13
14. 8.2.1 Transport
two constraints:
1. GET: no body to the 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
15. 15
GET with query string, body, header PATCH with query string, body, header
16. 16
HTTP Methods Query String Body HTTP Header
GET v v (?) v
PATCH v v v
Node.JS (express)
HTTP Methods Query String Body HTTP Header
GET v ?? v
PATCH v
ASP.NET (Kestrel)
18. have to augment the request
messages for both the standard
update method and standard get
method.
18
19. Does this idea of partial updates
and retrievals extend inside 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
20. How to represent field:
maxMessageCount
● JSON Path: $.loggingConfig.maxMEssageCount
20
21. 1. Separate parts of a field specification
must use a 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
24. 8.3.3 Repeated fields
● prefix of "administrators.*." as a way of
saying “For each administrator
● retrieve only the name of an administrator,
use a field mask value of
"administrators.*.name"
24
25. 8.3.4 Default values
the goal of a default value is 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
33. What does an unset field mask mean on a standard 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
41. ● the goal is still quite limited:
a. to minimize 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
44. 8.4.1 Universal support
44
● NOT at all a requirement that every API must support partial retrieval.
● more an issue of concurrency than resource size and complexity
47. 1. Partial retrieval is particularly important in cases where resources 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