Skip to content

registry rpc

Tim Burks edited this page Jan 21, 2023 · 5 revisions

The Registry API includes low-level methods that can be used to directly add information to a registry. These are illustrated below with registry rpc subcommands that make direct calls to methods of the Registry Service.

# Create an API entry in the registry.
registry rpc create-api \
  --api_id petstore \
  --parent projects/$PROJECT/locations/global \
  --json

# Create an entry for a version of the API that we just added.
registry rpc create-api-version \
  --api_version_id 1.0.0 \
  --parent projects/$PROJECT/locations/global/apis/petstore \
  --json

# Create an entry for a spec of this version and include the spec contents.
# Note that the mime type is required by downstream tools.
registry rpc create-api-spec \
  --api_spec_id openapi \
  --parent projects/$PROJECT/locations/global/apis/petstore/versions/1.0.0 \
  --api_spec.contents `xxd -c 10000 -p petstore.yaml` \
  --api_spec.filename "petstore.yaml" \
  --api_spec.mime_type "application/x.openapi?version=3" \
  --json

# List all of the specs in the registry.
# Note that the dashes (-) in the parent are wildcards.
registry rpc list-api-specs \
  --parent projects/$PROJECT/locations/global/apis/-/versions/- \
  --json

# Get metadata describing the API spec that we just uploaded.
registry rpc get-api-spec \
  --name projects/$PROJECT/locations/global/apis/petstore/versions/1.0.0/specs/openapi \
  --json

# Get the contents of the API spec.
registry rpc get-api-spec-contents \
  --name projects/$PROJECT/locations/global/apis/petstore/versions/1.0.0/specs/openapi \
  --json | jq .data -r | base64 -d