Search code examples
google-cloud-platformgcloudgoogle-cloud-iam

GCP: Resource Name vs URL : Inconsistent matching


For a Resource Name find the appropriate HTTP Rest URL for it.

With the help of the below Google Doc, for some resources name to URL mapping is working fine

Example:

Basically adding HTTPS scheme before the name and the API major version before the resource path this works fine.

But the problem is this conversion scheme is not consistent for some resources if we form URL with this approach it will differ from the actual URL

Example:

Compute Engine API Reference: https://cloud.google.com/compute/docs/reference/rest/v1

Other resources apart from compute also have actually different URL from the generated one using the above method.

Queries are:

  1. Apart from the mentioned way is there any way to map resource names to URL
  2. What are the best practices in such conversion
  3. Apart from manually mapping each name to URL is there any generic way
  4. Is there any API which provides this mapping, Like pass, a resource name and URL for it will be returned(On the internet I didn't found one)

Solution

  • Google APIs have a discovery document.

    In that JSON file, there are 2 fields revelant for this question: rootUrl and servicePath.

    To construct a proper URL for the API, concatenate both values.

    More details in the discovery service docs.