Skip to content

Commit

Permalink
feat(AIP-4223): add guidance on client-side validation (aip-dev#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored May 13, 2022
1 parent 884f09a commit 00c9302
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions aip/client-libraries/4223.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
id: 4223
state: approved
created: 2022-05-13
---

# Client-side payload validation

Client-side payload validation is the practice of inspecting the request payload
for any misconfigurations (e.g. missing required fields, attempting to update an
immutable field) prior to executing a network call with the payload. Typically,
documentation communicates the expectations of the service with regards to each
request field, including any requirements on presence or format. The
`google.api.field_behavior` annotation defined in [AIP-203][] is the
machine-readable format that services use to document behavior in relation to
specific request fields.

## Guidance

Client libraries **must not** implement client-side payload validation based
on the `google.api.field_behavior` annotation, except to prevent
[local failures](4223.md#local-failures).

The reason for this is that the `google.api.field_behavior` annotation is
primarily a machine-readable form of _documentation_, and **not** a
configuration for payload validation. The annotation conveys how the service
_already_ handles the field, and alludes to a service's own payload validation
or expectations.

Admittedly, depending on services to implement payload validation means clients
will sometimes make network calls that are bound to result in errors. Furthermore, users
then depend on services to provide actionable errors, when the client could have
provided a language-idiomatic, localized error. However, robust server-side
payload validation means that _all types_ of client (first party, third party,
`curl`, etc.) will benefit from the **same** validation, and that there is no
lag between service and clients when the field behavior changes.

### Local failures

Client libraries **may** implement client-side payload validation based on the
`google.api.field_behavior` annotation only to the extent that it prevents
local failures, such as crashes within the client library code itself.

[AIP-203]: ../general/0203.md

0 comments on commit 00c9302

Please sign in to comment.