Batch methods- Get
Some APIs need to allow users to get a specific set of resources at a consistent time point (e.g. using a read transaction). A batch get method provides this functionality.
Guidance
APIs may support batch get to retrieve a consistent set of resources.
- The method’s name must begin with
BatchGet
. The remainder of the method name must be the plural form of the resource being retrieved. - The HTTP verb must be
GET
. - The HTTP URI must end with
:batchGet
. - The URI path must represent the collection for the resource, matching the collection used for simple CRUD operations. If the operation spans parents, a wilcard may be accepted.
- There must not be a request body.
- If a GET request contains a body, the body must be ignored, and must not cause an error.
Request
The request for a batch get method should be specified with the following pattern:
- The request must include an array field which accepts the resource paths
specifying the resources to retrieve. The field must be named
paths
.- If no resource paths are provided, the API should error with
INVALID_ARGUMENT
. - The parameter must be required.
- The documentation for the parameter should include the resource type that it references.
- The parameter should define the pattern of the resource path values.
- The parameter should define the maximum number of paths allowed.
- If no resource paths are provided, the API should error with
- Batch Get should not support pagination because transactionality across API calls would be extremely difficult to implement or enforce, and the request defines the exact scope of the response anyway.
- The request must not contain any other required parameters, and should not contain other optional parameters except those described in this or another AEP.
-
The request schema must match the method name, with
Request
suffix. -
A
parent
field should be included, unless the resource being retrieved is a top-level resource, to facilitate inclusion in the URI as well to permit a single permissions check. If a caller sets this field, and the parent collection in the path of any resource being retrieved does not match, the request must fail.- This field should be required if only 1 parent per request is allowed.
- The field should identify the resource type that it references.
- The comment for the field should document the resource pattern.
-
There must not be a body key in the
google.api.http
annotation.
-
The
paths
parameter must be a query parameter which accepts an array of resource paths specifying the resources to retrieve.- If no resource paths are provided, the API should error with status
code
400 Bad Request
. - If the collection in the path of any resource does not match the collection of the request URL, the request must fail.
- If no resource paths are provided, the API should error with status
code
-
The method definition must not have a
requestBody
defined.
Response
The response for a batch get method must be specified with the following pattern:
- The response schema must match the method name, with
Response
suffix. - The response schema must have a single array property where each item is either a retrieved resource or an error structure describing an error that occurred attempting to retrieve the resource. The error alternative would only be present for non-transactional batch gets.
- The order of resources/error objects in the response must be the same as the paths in the request.
- The array of resources must be named
results
and contain resources with no additional wrapping. - There must not be a
nextPageToken
field as batch get operations are not pageable.
Example response body:
Support for transactional get
The batch get method may support a transactional form of operation where the
get either succeeds for all requested resources or fails. When supported, the
method must define a boolean parameter transactional
that the user must
specify with the value true
to request a transactional operation.
Changelog
- 2024-04-22: Adopt from Google AIP https://google.aip.dev/231 with the
following changes:
- Dropped the “nested requests” pattern.
- Changed the response schema to an object with
results
array property. - Made transactional operation optional and controlled by asTransaction parameter.