Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions aip/general/0159/aip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Reading across collections

Sometimes, it is useful for a user to be able to retrieve resources across
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Sometimes, it is useful for a user to be able to retrieve resources across
Sometimes it is useful for a user to be able to retrieve resources across

multiple collections, or retrieve a single resource without needing to know
what collection it is in.

## Guidance

APIs **may** support reading resources across multiple collections by allowing
users to specify a `-` (the hyphen or dash character) as a wildcard character
in a standard [`List`][aip-132] operation:

```
GET /v1/publishers/-/books?filter=...
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • @mkistler Maybe suggest both the Google and IBM approach, with guidance to pick one.
    • Maybe suggest the rationale behind both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot what the IBM approach was. :-(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The IBM approach is creating a new top-level collection.

```

- The URI pattern **must** still be specified with `*` and permit the
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is protobuf specific.

collection to be specified; a URI pattern **must not** hard-code the `-`
character.
- The operation **must** explicitly document that this behavior is supported.
- The resources provided in the response **must** use the canonical name of the
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has some Google-specific assumptions about what a name is, and why the name would contain the parent ID at all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That said, if a parent ID is provided, it should be filled out (publisher_id should never come back as -).

resource, with the actual parent collection identifiers (instead of `-`).
- Services **may** support reading across collections on `List` requests
regardless of whether the identifiers of the child resources are guaranteed
to be unique.
- However, services **must not** support reading across collections on `Get`
requests if the child resources might have a collision.
- Cross-parent requests **should not** support `order_by`. If they do, the
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems very Google-specific because Google uses this most often for locations. For situations where there is a single backend / database, this guidance is unimportant.

field **must** document that it is best effort. This is because cross-parent
requests introduce ambiguity around ordering, especially if there is
difficulty reaching a parent (see AIP-217).

**Important:** If listing across multiple collections introduces the
possibility of partial failures due to unreachable parents (such as when
listing across locations), the operation **must** indicate this following the
guidance in AIP-217.

### Unique resource lookup

Sometimes, a resource within a sub-collection has an identifier that is unique
across parent collections. In this case, it may be useful to allow a
[`Get`][aip-131] operation to retrieve that resource without knowing which
parent collection contains it. In such cases, APIs **may** allow users to
specify the wildcard collection ID `-` (the hyphen or dash character) to
represent any parent collection:

```
GET https://example.googleapis.com/v1/publishers/-/books/{book}
```

- The URI pattern **must** still be specified with `*` and permit the
collection to be specified; a URI pattern **must not** hard-code the `-`
character.
- The operation **must** explicitly document that this behavior is supported.
Comment on lines +64 to +67
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these lines can be deleted as they seem to simply restate lines 23-25

Suggested change
- The URI pattern **must** still be specified with `*` and permit the
collection to be specified; a URI pattern **must not** hard-code the `-`
character.
- The operation **must** explicitly document that this behavior is supported.

- The resource name in the response **must** use the canonical name of the
resource, with actual parent collection identifiers (instead of `-`). For
example, the request above returns a resource with a name like
`publishers/123/books/456`, _not_ `publishers/-/books/456`.
- The resource ID **must** be unique within parent collections.

## Further reading

- For partial failures due to unreachable resources, see AIP-217.
7 changes: 7 additions & 0 deletions aip/general/0159/aip.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
id: 159
state: approved
created: 2019-07-26
placement:
category: design-patterns
order: 70