Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction 📝
2.
Google Cloud APIs 🎫 
3.
Google Enterprise APIs 💡
4.
Getting started with APIs 🌐
4.1.
🔖Creating a Google account
4.2.
🔖Creating a Google project
4.3.
🔖Discovering APIs
4.4.
🔖Enabling APIs
4.5.
🔖Enabling billing
4.6.
🔖Getting application credentials
4.7.
🔖Using application credentials
4.8.
🔖Building applications
5.
Capping API usage 🎛️
5.1.
🔖Change the limits on the number of requests
5.2.
🔖Limiting requests per user
5.3.
View and edit all quotas for cloud APIs in Project
6.
Monitoring API usage 🖥️
6.1.
🔖Using the API Dashboard
6.2.
🔖Using Cloud Monitoring
7.
Troubleshooting API usage📝
8.
HTTP guidelines ⚙️
8.1.
🔖Working with wire protocols (HTTP/*)
8.1.1.
HTTP semantics📍
8.1.2.
HTTP versions📍
8.1.3.
Channels📍
8.1.4.
HTTPS📍
9.
System parameters🖥️
9.1.
🔖HTTP Mapping
9.2.
🔖gRPC Mapping
10.
Frequently Asked Question❓
10.1.
What is Google Cloud API?
10.2.
What are two ways of Monitoring API usage?
10.3.
How Google Cloud API works?
10.4.
What is an API?
10.5.
What is the purpose of an API?
11.
Conclusion ✉️
Last Updated: Mar 27, 2024

Cloud APIs

Author Alok Pandey
0 upvote

Introduction 📝

Google services offer networked APIs under the name Google APIs. Applications from various settings can use JSON HTTP and gRPC to access Google APIs. We advise developers to incorporate client libraries from Google into their programs. By implementing basic boilerplate functionality, like authentication and list pagination, these libraries significantly lower the amount of work required for development and common errors. In this article, we will discuss Google Cloud APIs and how to get started with cloud APIs, along with their monitoring and capping the usage of APIs.

Google Cloud APIs 🎫 

The Google Cloud APIs provide programmatic access to Google Cloud Platform services. They are an important component of the Google Cloud Platform, letting you effortlessly add the power of computing, networking, storage, and machine-learning-based data analysis to your apps.

Google Cloud APIs

Customers can access cloud APIs through network API services such as the Cloud Pub/Sub API. Each Cloud API typically runs on one or more subdomains of Googleapis.com, such as pubsub.googleapis.com, and provides JSON HTTP and gRPC interfaces to clients over the public internet and Virtual Private Cloud (VPC) networks. Clients can use client libraries or submit HTTP and gRPC requests directly to Cloud API endpoints.

Google Enterprise APIs 💡

They are High-stability APIs. Ready for enterprise use. For the sake of its clients, Google Cloud is constantly enhancing its APIs and solutions. Based on the following characteristics, Google Enterprise APIs

Stability: These APIs offer the high stability needed to maintain the essential systems of our customers. They follow a new, more stringent methodology that takes into account the crucial, long-term reliance on APIs that our clients have. Deprecation and breaking changes will be handled carefully as part of our commitment to ensure API stability. Changes to these APIs are handled selectively and wisely, giving affected customers enough warning and support, as well as offering alternatives and migration tools.
 

Enterprise: These APIs aspire to increase the shared trust between our clients, which is essential for long-term investments and us. We want our customers to feel confident enough to construct original new apps on top of our top-notch infrastructure with the aid of our cutting-edge services and equipment.
 

Support: The following customer help alternatives are offered for problems with these APIs from users:
 

Google Cloud Platform: The customer Support team offers dedicated support to customers of the Google Cloud Platform API, including code assistance and implementation.

 

Google Workspace: Customers of the Google Workspace API receive specialized support for the broad functionality of these APIs.
 

Google Maps Platform: The customer Support team offers users of the Google Maps API devoted support, including coding guidance and implementation.

Getting started with APIs 🌐

In this section, we will discuss how developers can get started using Google Cloud APIs.

If this is your first time using Google Cloud APIs, you can use the instructions in this manual to call the APIs using curl commands. Before creating your application, you can explore with an API using curl instructions.

🔖Creating a Google account

You must initially have a Google account in order to use Google Cloud APIs in your projects. This gives you access to Google developer tools like the Google Cloud Console, gcloud CLI, Cloud Logging, and Cloud Monitoring. Create an account if you're new to Google Cloud to see how well our products work in practical situations. Additionally, new users receive $300 in complimentary credits to run, test, and deploy workloads.

🔖Creating a Google project

You also need to have a Google project in order to access Cloud APIs. An equivalent of a developer account is a project. It acts as a resource container for the resources you have on Google Cloud. Additionally, it creates a boundary of isolation for your use of Google Cloud services, allowing you to handle pricing and quotas independently at the project level. Dashboards and use telemetry are also organized into groups by projects. You can create a project via the console if you don't already have one.

🔖Discovering APIs

Use the Google Cloud console API Library to examine the available Cloud APIs and choose the ones that best suit your business needs before using any Cloud APIs. Visit a Cloud API's public documentation website, like Spanner API, for further details.

🔖Enabling APIs

You must enable a Cloud API for your project in order to use it. You might need to activate an API for many projects, depending on the services and projects your application uses, including the client project and resource projects.

To enable an API for a project using the console:

  1. Visit the API Library for the console.
  2. Choose the project you want to use from the list of projects.
  3. Choose the API you want to activate from the API Library. Use the search bar and/or the filters if you need assistance finding the API.
  4. Click ENABLE on the API page.

You can also enable and disable Cloud APIs using the gcloud CLI and the Service Usage API:

$ gcloud services enable pubsub.googleapis.com
$ gcloud services disable pubsub.googleapis.com

🔖Enabling billing

Some Cloud APIs include usage fees. Before you may begin using these APIs in your project, billing must be enabled for it. The billing account connected to the project receives a fee for any API access.

Visit the console billing page and follow the instructions to create a billing account if you don't already have one. Then associate your project with your billing account.

🔖Getting application credentials

Only registered applications are permitted to submit API queries to cloud APIs. This criterion enables API producers to link and track API usage to the appropriate application-owning project.

🔖Using application credentials

Before developing any application code, if you are unfamiliar with Google Cloud APIs, we strongly advise you to explore your application credentials and Cloud APIs using oauth2l. Any application credentials accepted by oauth2l can be used to access Google Cloud APIs by using the curl command.

oauth2l curl --credentials ./creds.json --scope cloud-platform --url https://pubsub.googleapis.com/v1/projects/my-project-id/topics -- -v

🔖Building applications

If Google Cloud Client Libraries are offered, we advise using them if you're creating an application with Cloud APIs. For your convenience, the client libraries can handle functionalities of the common API, including authentication, error handling, retry, and payload validation. In order for the client libraries to contact Google Cloud APIs on your behalf, you must provide your application credentials to them during initialization.

Capping API usage 🎛️

Depending on the API, you can specifically control requests by capping the number of requests made per day, per minute, or per user per minute.

You might want to create caps to restrict billable consumption. You can establish requests per day caps, for instance, to avoid being charged for usage that exceeds the free courtesy usage restrictions.

🔖Change the limits on the number of requests

Any billable API that accepts requests can have its limits configured. Although most APIs have default limits, you can adjust them up to a Google-set maximum. Until your app enables billing, several APIs establish a low cap.
 

  1. Navigate to the APIs & Services Dashboard page in the console.
     
  2. Choose a project from the list of projects or start a new one.
     
  3. Select the desired API by clicking its name.
     
  4. Select Quotas. The absence of the Quotas tab in the tab navigation indicates that there are no defined quotas for the API you've chosen.
     
  5. Enter the relevant characteristics and values in the filter list Filter field to locate the quota you want to cap. For instance, type Quota: Subnetworks to find the Subnetworks quota.
     
  6. To cap a quota, tick the box next to it, then click CREATE EDIT QUOTAS.
     
  7. Fill out the quota modification form completely, including the new cap you want to impose.
     
  8. Simply press SUBMIT REQUEST.

🔖Limiting requests per user

Some APIs have a default per user per minute cap to protect individual users from exceeding your API quota. If there is such a default limit, you can change it as explained in the previous section to restrict the amount of quota that each user is permitted to use.

Only requests per user per minute are capped using the quotaUser parameter. Calls cannot be capped by the user if the quotaUser argument is not sent since otherwise all calls will be attributed to your server machines.

View and edit all quotas for cloud APIs in Project

By visiting the Quotas page in the IAM & Admin area of the console, you may examine, modify, and ask for greater quota limits for all billable APIs in a certain project.

  1. Navigate to the Quotas page in the console.

Go to Quotas

  1. Choose a project from the list of projects or start a new one. Each sort of quota that is offered in each service is listed as a line item on the Quotas page for the project that was chosen.
     
  2. Click the Filter table to query your quota by a specific property.
     
  3. The quota(s) you want to change are marked with a checkmark. Some of the checkboxes cannot be selected unless billing is enabled for the project.
     
  4. Click edit EDIT QUOTAS.
     
  5. Expand the service view in the Quota adjustments pane that appears, make any necessary quota edits, and then click DONE.
     
  6. Repeat to edit the quotas for each service you've chosen.
    1. The input boxes are already filled with the current quota limits.
    2. There are input errors for a service with an alert icon (error) on submission.
    3. By selecting them as previously, you can set more quotas for editing.
    4. By highlighting the unexpanded service view and selecting the delete icon while your cursor is over it, you can remove a service from the Quota changes pane (delete).
       
  7. Click NEXT once you are finished editing quotas.
     
  8. If your request for a quota edit needs to be reviewed, the Contact information form appears. Specify your contact information on the form..
     
  9. Simply press SUBMIT REQUEST.

Monitoring API usage 🖥️

API Dashboard and Cloud Monitoring are two locations where you can view API metrics. The metrics you see are particular to your project and do not represent the broader state of the service.

🔖Using the API Dashboard

Using the API Dashboard in the Google Cloud console is the simplest way to see your API stats. You can view a summary of all your API usage or drill down to view your use of a particular API.

🔖Using Cloud Monitoring

If you use Cloud Monitoring, you can use Metrics Explorer to go deeper into the available metrics data to have a better understanding of how your API is being used. Numerous indicators are supported by Cloud Monitoring, which you can combine with filters and aggregations to provide fresh, illuminating perspectives on the performance of your applications. For instance, you can create a dashboard that displays error rates over time by combining a request count metric with a filter on the HTTP Response Code class, or you can look at the 95th percentile latency of calls to the Cloud Pub/Sub API.

Troubleshooting API usage📝

Google services offer networked APIs under the name Google APIs. Applications from various settings can use JSON HTTP and gRPC to access Google APIs.By implementing basic boilerplate functionality, like authentication and list pagination, these libraries significantly lower the amount of work required for development and common errors.

To solve these common problems we should take care of the following things:

Basic Troubleshooting: Sending test requests to the Google APIs you intend to use should be done first using the curl -v command. You can use it to test out Google APIs without having to write any code. Before you begin actual application development, you may frequently fix a lot of problems.

Troubleshooting using metrics: Free API metrics are available from Google APIs for common API usage data like request counts, failures, latencies, and request and response sizes. Regarding applications and places, they offer fine-grained dimensions. Developers can find instances of unusual API usage and pinpoint potential causes.

Troubleshooting using logs: Logs often have more details about mistakes, such as error messages and error details, than metrics do. They are incredibly helpful and frequently required to fix API problems. Developers can query the logs to uncover error messages and error details when they discover a problem with their API usage. They can then utilize this information to fix the problem themselves or to get in touch with support.

Cloud Audit Logs: Google Cloud products may produce audit logs that contain specific information about the activity for security-sensitive operations. For advice on how to debug your use of Google Cloud APIs, consult them. For instance, the dry run capability of VPC Service Controls creates audit logs for administrators to assess the impending policy changes.

Resolving errors: If you are having problems using the Google API and you have located the relevant metrics and logs, you can follow the instructions on the API Design Guide Errors page to fix the problems.

Each API error typically has three pieces of information: the error code, the error message, and the error details.
 

  • Applications can retry after 503 errors or re-authenticate users after 401 errors thanks to the error code, which enables higher-level error handling.
     
  • Application developers can understand the issue and correct the logic in their applications by using the error message.
    Code against the error messages with caution as they are subject to change at any time.
     
  • The apps can use the additional information in the error details to handle the error programmatically.

HTTP guidelines ⚙️

In this section, we will describe how Google APIs work with different HTTP versions and implementations.

If you are a skilled developer and need to create your own original code in order to directly access an API's REST interface with the help of a third-party HTTP client library of your choice, you should comprehend at least some of the semantics described here (as applicable to your chosen API), in addition to understanding the features offered by your HTTP library.

🔖Working with wire protocols (HTTP/*)

This section outlines the supported wire protocols (usually a variation of HTTP) that Cloud APIs can use, as well as the best practices for using them.

HTTP semantics📍

Be sure to adhere to accepted HTTP protocol semantics while writing API client code. Only a portion of the basic HTTP functionality may be supported by server-side proxies or API stacks, together with any backward-compatible modifications.

The server stack controls the HTTP protocol semantics that must be addressed by API server-side implementations. You should only rely on such semantics if capabilities like cache support are specifically described in the API spec.

HTTP versions📍

Any HTTP/* protocol may be used by clients, provided that it is permitted by the client platform, the client-side network, or the server-side proxy. QUIC, SPDY/*, HTTP/2, HTTP/1.0, and HTTP/1.1 are among the supported protocols.

Server-push and priority are two API capabilities that may only be enabled by more recent HTTP protocols, and full-duplex streaming is only completely specified with HTTP/2. If you require any of these features as part of the API specification, be aware of the restrictions imposed by various HTTP versions.

Channels📍

L4 network connections are referred to as channels (TCP or UDP sockets). Client programs shouldn't make any assumptions about how HTTP requests are handled by channels during runtime. Channels are typically terminated by proxies acting on behalf of the server process.

HTTPS📍

Clients can use HTTP or HTTPS to access an API, as specified by the API specification. Client apps are transparent to TLS negotiation and TLS versions. Google APIs only permit HTTPS traffic by default.

System parameters🖥️

All Google APIs created utilizing the platform receive a set of common capabilities from Google's API platform. The platform pre-defines a special set of request parameters called system parameters in order to use and manage such capabilities. These options are accessible through all gRPC and REST APIs from Google. Either an HTTP query parameter or an HTTP header can be used to specify a system parameter. One and only HTTP headers are provided by Google gRPC APIs.

Most users won't need to explicitly use these options. However, client libraries offered by Google frequently make use of them. The system parameters can be helpful if you need to create custom code to directly contact Google APIs in situations like regulating JSON pretty-printing or specifying API Keys.

🔖HTTP Mapping

System parameters are transmitted as HTTP request headers or URL query parameters for HTTP requests. If you have a system parameter called $foo, for instance, it would be delivered as $foo, it's sent as ?$foo=xxx in the URL, or ?%24foo=xxx if URL-encoded. The details are in the table below.

🔖gRPC Mapping

System parameters are given as HTTP request headers with lowercase keys for gRPC requests. The details are in the table below.
 

URL Query Parameter

HTTP/gRPC Header

Description Of header 

-

Authorization Header

Authentication credentials. You can see the Authentication overview for details.

$alt,

alt

-

Alternative response format. Supported values are JSON (default), media, and proto.

$.xgafv

-

JSON error format. Supported values are one, two (default). The error format 1 should only be used by Google API Client Libraries.

$callback,

callback

-

JSONP callback parameter.

$ct

Content-Type

HTTP Content-Type request header override.

$fields,

fields

X-Goog-FieldMask

FieldMask used for response filtering. If empty, all fields should be returned unless documented otherwise.

-

X-HTTP-Method-Override

The intended HTTP method for the request. Some network proxies don't accept all HTTP methods.

$key,

key

X-Goog-Api-Key

Google API key. See https://cloud.google.com/docs/authentication/api-keys for details.

passwd,

password

-

Reserved to prevent putting passwords in URLs.

$prettyPrint,

prettyPrint

-

Pretty-print JSON response. Supported values are true (default), false.

quotaUser

X-Goog-Quota-User

A pseudo user identifier for charging per-user quotas. If not specified, the authenticated principal is used. If there is no authenticated principal, the client's IP address will be used. When specified, a valid API key with service restrictions must be used to identify the quota project. Otherwise, this parameter is ignored.

$outputDefaults

-

Force to output proto default values for JSON responses.

$unique

-

Unique query parameter to disable request caching.

-

X-Goog-Api-Client

API client identification. The value is a space-separated list of NAME "/" SEMVER strings, where the NAME should only contain lowercase letters, digits, and "-", and the SEMVER should be a semantic version string. For example: X-Goog-Api-Client: python/3.5.0 grpc-google-pubsub-v1/0.1.0-beta2 linux/2.7.0.

-

X-Goog-Request-Reason

Contains a reason for making the request, which is intended to be recorded in audit logging. An example reason would be a support-case ticket number.

$userProject

X-Goog-User-Project

A caller-specified project for quota and billing purposes. The caller must have serviceusage.services.use permission on the project.

-

X-Server-Timeout

Timeout (in seconds, float value) for the server to finish processing the request. This system param only applies to REST APIs for which client-side timeout is not applicable.

-

x-goog-request-params

Passing additional parameters for gRPC requests in URL query format. For example: x-goog-request-params: service=pubsub.googleapis.com&release=2021-11-01r0.

Frequently Asked Question❓

What is Google Cloud API?

You can use cloud APIs to automate workflows in the language of your choice. REST calls or client libraries are written in well-known programming languages that can be used with these cloud APIs.

What are two ways of Monitoring API usage?

We can monitor API usage by using the API dashboard and Cloud monitoring.

How Google Cloud API works?

Google Cloud API is an essential component of the Google Cloud Platform, enabling you to quickly and inexpensively add the power of everything from processing to networking to storage to machine learning-based data analysis to your apps.

What is an API?

The term "API" stands for application programming interface and is used by software and applications to communicate with other applications or software. In simple terms, it is a software bridge that enables the communication between two applications.

What is the purpose of an API?

Application Programming Interface (API), is a software intermediary which helps any two applications to communicate with each other.

Conclusion ✉️

In this article, we have extensively discussed Cloud APIs. We discussed Getting started with APIs and how to monitor them. If you would like to learn more, check out our articles on
 

Refer to our guided paths on Coding Ninjas Studio to learn more about DSA, Competitive Programming, JavaScript, System Design, etc. 

Enroll in our courses and refer to the mock test and problems available.

Take a look at the interview experiences and interview bundle for placement preparations.

Conclusion Image

Do upvote our blog to help other ninjas grow. 

Happy Coding!

Live masterclass