In many APIs, it is customary to make a GET
request to a collection's URI (for example, /v1/publishers/1/books
) in order to retrieve a list of resources, each of which lives within that collection.
Resource-oriented design (AIP-121) honors this pattern through the List
method. These RPCs accept the parent collection (and potentially some other parameters), and return a list of responses matching that input.
APIs must provide a List
method for resources unless the resource is a singleton. The purpose of the List
method is to return data from a finite collection (generally singular unless the operation supports reading across collections).
List methods are specified using the following pattern:
rpc ListBooks(ListBooksRequest) returns (ListBooksResponse) {
option (google.api.http) = {
get: "/v1/{parent=publishers/*}/books"
};
option (google.api.method_signature) = "parent";
}
List
. The remainder of the RPC name should be the plural form of the resource being listed.Request
and Response
suffixes.GET
.parent
, and should be the only variable in the URI path. All remaining parameters should map to URI query parameters.books
in the above example) must be a literal string.body
key in the google.api.http
annotation must be omitted.google.api.method_signature
annotation, with a value of "parent"
. If the resource being listed is a top-level resource, there should be either no google.api.method_signature
annotation, or exactly one google.api.method_signature
annotation, with a value of ""
.List methods implement a common request message pattern:
message ListBooksRequest {
// The parent, which owns this collection of books.
// Format: publishers/{publisher}
string parent = 1 [
(google.api.field_behavior) = REQUIRED,
(google.api.resource_reference) = {
child_type: "library.googleapis.com/Book"
}];
// The maximum number of books to return. The service may return fewer than
// this value.
// If unspecified, at most 50 books will be returned.
// The maximum value is 1000; values above 1000 will be coerced to 1000.
int32 page_size = 2;
// A page token, received from a previous `ListBooks` call.
// Provide this to retrieve the subsequent page.
//
// When paginating, all other parameters provided to `ListBooks` must match
// the call that provided the page token.
string page_token = 3;
}
parent
field must be included unless the resource being listed is a top-level resource. It should be called parent
.
page_size
and page_token
fields, which support pagination, must be specified on all list request messages. For more information, see AIP-158.
page_size
field should document the maximum allowed value, as well as the default value if the field is omitted (or set to 0
). If preferred, the API may state that the server will use a sensible default. This default may change over time.INVALID_ARGUMENT
error.page_token
field must be included on all list request messages.string filter
and string order_by
.Note: List methods should return the same results for any user that has permission to make a successful List request on the collection. Search methods are more relaxed on this.
Response messageList methods implement a common response message pattern:
message ListBooksResponse {
// The books from the specified publisher.
repeated Book books = 1;
// A token, which can be sent as `page_token` to retrieve the next page.
// If this field is omitted, there are no subsequent pages.
string next_page_token = 2;
}
next_page_token
field, which supports pagination, must be included on all list response messages. It must be set if there are subsequent pages, and must not be set if the response represents the final page. For more information, see AIP-158.int32 total_size
(or int64 total_size
) field with the number of items in the collection.
total_size
field should reflect the size of the collection after the filter is applied.List
methods may allow clients to specify sorting order; if they do, the request message should contain a string order_by
field.
"foo,bar"
." desc"
suffix; for example: "foo desc, bar"
."foo, bar desc"
, " foo , bar desc "
, and "foo,bar desc"
are all equivalent..
character, such as foo.bar
or address.street
.order_by
definition.
Timestamp
and Duration
are compared as their representative type; Timestamp
is compared as time e.g. before or after, Duration
is compared as a quantity e.g. more or less.Note: Only include ordering if there is an established need to do so. It is always possible to add ordering later, but removing it is a breaking change.
FilteringList methods may allow clients to specify filters; if they do, the request message should contain a string filter
field. Filtering is described in more detail in AIP-160.
Note: Only include filtering if there is an established need to do so. It is always possible to add filtering later, but removing it is a breaking change.
Soft-deleted resourcesSome APIs need to "soft delete" resources, marking them as deleted or pending deletion (and optionally purging them later).
APIs that do this should not include deleted resources by default in list requests. APIs with soft deletion of a resource should include a bool show_deleted
field in the list request that, if set, will cause soft-deleted resources to be included.
See errors, in particular when to use PERMISSION_DENIED and NOT_FOUND errors.
Further readingRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.5