Skip to content

Commit

Permalink
feat(update): remove create or update
Browse files Browse the repository at this point in the history
create or update introduces a new pattern in addition
to the existing flow of:

1. getting a resource.
2. if NOT_FOUND, send a create.
3. if found, send an update.

In the future, this could be re-added as an Apply method,
which would map to the appropriate REST method of PUT.
  • Loading branch information
toumorokoshi committed Nov 22, 2024
1 parent eb3e255 commit 68771d0
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions aep/general/0134/aep.md.j2
Original file line number Diff line number Diff line change
Expand Up @@ -170,51 +170,6 @@ If a rating were set on a book and the existing `PUT` request were executed, it
would wipe out the book's rating. In essence, a `PUT` request unintentionally
would wipe out data because the previous version did not know about it.

### Create or Update

If the service uses client-assigned resource paths, `Update` methods **may**
expose a `bool allow_missing` field, which will cause the method to succeed in
the event that the user attempts to update a resource that is not present (and
will create the resource in the process).

{% tab proto %}

```proto
message UpdateBookRequest {
// The book to update.
//
// The book's `path` field is used to identify the book to be updated.
// Format: publishers/{publisher}/books/{book}
Book book = 1 [(google.api.field_behavior) = REQUIRED];

// The list of fields to be updated.
google.protobuf.FieldMask update_mask = 2;

// If set to true, and the book is not found, a new book will be created.
// In this situation, `update_mask` is ignored.
bool allow_missing = 3;
}
```

{% tab oas %}

**Note:** OAS example not yet written.

{% endtabs %}

More specifically, the `allow_missing` flag triggers the following behavior:

- If the method call is on a resource that does not exist, the resource is
created. All fields are applied regardless of any provided field mask.
- However, if any required fields are missing or fields have invalid values,
an `INVALID_ARGUMENT` error is returned.
- If the method call is on a resource that already exists, and all fields
match, the existing resource is returned unchanged.
- If the method call is on a resource that already exists, only fields declared
in the field mask are updated.

The user **must** have the update permissions to call `Update` even with
`allow_missing` set to `true`.

### Etags

Expand Down

0 comments on commit 68771d0

Please sign in to comment.