CC07-Practice_2-REST_API_Applications
CC07-Practice_2-REST_API_Applications
Hồ Chí Minh
Ngành Hệ Thống Thông Tin
More:
▪ Rajkuma Buyya, Jame Broberg and Andrzej Goscinski. 2011. Cloud Computing –Principles and paradigms, Wiley
▪ Nick Antonopoulos, and Lee Gillam. 2010. Cloud Computing - Principles, Systems and Applications, Springer-
Verlag London Limited.
▪ Slides here are modified from several sources in Universities and Internet.
4
Cloud Computing: Practices
5
Cloud Computing: Practices
.
6
Content of Practice 2
7
Cloud RESTfull-API and Applications
❑ REST and API:
▪ REST (Representational State Transfer) is a style of software architecture that provides a convenient and consistent
approach to requesting and modifying data.
▪ REST works over the HTTP protocol that provides communication between client-server. REST is a transfer method
used in software based on service-oriented architecture.
▪ REST is an API that defines a set of functions that programmers can use to send requests and receive responses
using the HTTP protocol methods such as GET and POST. In the context of Google APIs, it refers to using HTTP
verbs to retrieve and modify representations of data stored by Google.
▪ In a RESTful system, resources are stored in a data store; a client sends a request that the server perform a
particular action (such as creating, retrieving, updating, or deleting a resource), and the server performs the action
and sends a response, often in the form of a representation of the specified resource.
▪ Rest services:
o They are platform-independent.
(It doesn’t matter if the client is Windows, and the server is Linux)
o They are language independent.
o They work over HTTP.
o They are flexible and can be extended very easily. 8
Cloud RESTfull-API and Applications
❑ REST and API:
▪ REST is an API that defines a set of functions that programmers can use to send requests and receive responses
using the HTTP protocol methods such as GET and POST. In the context of Google APIs, it refers to using HTTP
verbs to retrieve and modify representations of data stored by Google.
9
Cloud RESTfull-API and Applications
❑ REST API:
▪ REST API can be used by any site or application no matter what language it is written in because the requests are
based on the universal HTTP protocol, and the information is usually returned in the JSON format that almost all of
the programming languages can read.
10
Cloud RESTfull-API and Applications
❑ REST, API, REST API:
11
Cloud RESTfull-API and Applications
❑ REST API:
▪ REST API can be used by any site or application no matter what language it is written in because the requests are
based on the universal HTTP protocol, and the information is usually returned in the JSON format that almost all of
the programming languages can read.
12
Cloud RESTfull-API and Applications
❑ Get started with REST for Google Photos APIs:
▪ To start using the Google Photos Library API, configure your project by enabling the API via the Google API Console
and setting up an OAuth 2.0 client ID.
▪ Your application interacts with Google Photos on behalf of a Google Photos user. For instance, when you create
albums in a user's Google Photos library or upload media items to a user's Google Photos account, the user
authorizes these API requests via the OAuth 2.0 protocol.
▪ The OAuth 2.0 client ID allows your application users to sign in, authenticate, and thereby use the Library API. The
Library API does not support service accounts; to use this API, users must be signed in to a valid Google Account.
✓ Testing
https://developers.google.com/photos/library/samples
13
Cloud RESTfull-API and Applications
❑ REST, API, REST API:
14
Google Cloud APIs
❑ Google Cloud APIs are programmatic interfaces to Google Cloud Platform services. They are a key part of Google
Cloud Platform, allowing you to easily add the power of everything from computing to networking to storage to
machine-learning-based data analysis to your applications.
❑ Cloud APIs are exposed as network API services to customers, such as Cloud Pub/Sub API. Each Cloud API
typically runs on one or more subdomains of googleapis.com, such as pubsub.googleapis.com, and provides both
JSON HTTP and gRPC interfaces to clients over public internet and Virtual Private Cloud (VPC) networks.
❑ Clients can send HTTP and gRPC requests to Cloud API endpoints directly or by using client libraries.
❑ To see available Cloud APIs, see Google Cloud APIs in the Google Cloud console API Library.
15
Google Cloud APIs
❑ Accessing Cloud APIs:
▪ You can access Cloud APIs from server applications with our client libraries in many popular programming
languages, from mobile apps via the Firebase SDKs, or by using third-party clients. You can also access Cloud APIs
with the Google Cloud CLI tools or Google Cloud console.
▪ If you are new to Cloud APIs, see Getting Started on how to use Cloud APIs.
https://cloud.google.com/apis/docs/getting-started
16
Google Cloud APIs
❑ API Design Guide:
▪ Regardless of the interface type, all Cloud APIs use resource-oriented design principles as described in our API
Design Guide, which ensures Cloud APIs to have a simple and consistent developer experience.
https://cloud.google.com/apis/design
▪ You can reference our API Design Guide to have a better understanding of Cloud APIs.
If you want to study the interface definition of Cloud APIs, you can visit the Google APIs repository on GitHub.
https://github.com/googleapis/googleapis
17
Google Cloud APIs
❑ Capping your API usage:
▪ Cloud APIs are shared among millions of developers and users. To ensure fair usage and minimize
abuse risks, all Cloud APIs are enforcing rate limits and resource quotas on usage, commonly known as
quotas.
▪ You can also use these quotas to control your spending on Google Cloud products by reducing your
own quota limits.
▪ If you need more quotas than the default limits, you need to file quota increase requests.
18
Google Cloud APIs
❑ Capping your API usage:
▪ Depending on the API, you can explicitly cap requests by limiting the requests per day, requests per
minute, or requests per minute per user.
▪ You might want to limit the billable usage by setting caps. For example, to prevent getting billed for
usage beyond the free courtesy usage limits, you can set requests per day caps.
▪ Individual users are identified by a unique string. If you're creating a server-side application (where the calling code
is hosted on a server that you own) that makes requests on behalf of users, your requests must include the
quotaUser parameter.
19
Google Cloud APIs
❑ Capping your API usage:
▪ Modify the limits on the number of requests
You can set limits to all requests to any billable API. Most APIs set default limits, but you can change that
limit up to a maximum specified by Google. Some APIs set a low limit until you enable billing on your project.
20
Google Cloud APIs
❑ Capping your API usage:
▪ View and edit all quotas for APIs in a project
You can review, edit, and request higher quota limits for all billable APIs in a given project by viewing the Quotas page
in the IAM & Admin section of Google Cloud console.
21
Monitoring API usage
❑ Using the API Dashboard:
▪ The simplest way to view your API metrics is to use the Google Cloud console's API Dashboard. You
can see an overview of all your API usage, or you can drill down to your usage of a specific API.
3. Median latency: the median latency for requests to enabled APIs, if available".
22
Monitoring API usage
❑ Using Cloud Monitoring:
▪ If you use Cloud Monitoring, you can dive deeper into available metrics data using the Metrics Explorer to give you
greater insight into your API usage. Cloud Monitoring supports a wide variety of metrics, which you can combine
with filters and aggregations for new and insightful views into your application performance.
To see API metrics in Metrics Explorer, select Consumed API as the resource type, then select one of the
serviceruntime metrics. Then use the filter and aggregation options to refine your data. After you've found the API
usage information you want, you can use Cloud Monitoring to create custom dashboards and alerts that will help you
continue to monitor and maintain a robust application. You can find out how to do this in the following pages:
o Building charts
o Introduction to alerting
o Managing alerting policies
23
Google Cloud APIs
❑ Best practices:
While API metrics are an extremely useful tool, there are issues you need to consider to make sure they provide useful
information, particularly when setting up alerts based on metric values. The following best practices will help you get
the most from API metrics data.
▪ Is latency causing a problem?
While some services are quite latency-sensitive, for others scale and reliability matter more. With data from API
metrics, you can learn what your users need from a given service.
▪ Traffic rate
API metrics are most useful where you have a high volume of traffic going to the API. If you call a service only
intermittently, your API metrics won’t be statistically valid and won’t give you meaningful triage information.
24
Google Cloud APIs
❑ Client libraries explained:
Client libraries make it easier to access Google Cloud APIs from a supported language. While you can use Google
Cloud APIs directly by making raw requests to the server, client libraries provide simplifications that significantly reduce
the amount of code you need to write.
This document explains the different types of client libraries that Google provides for Cloud APIs. You can also find out
more about the available libraries for your product or language of choice in the product or language's documentation.
You can find installation instructions and reference material for the Cloud Client Library on the Client Libraries page for
the Cloud APIs you're using. You can find links to get started with the Cloud Client Libraries and their reference 25
documentation on the Cloud Client Libraries page.
Cloud Monitoring - Report
TASK I: Google API Cloud
☺ Trình tự các bước thực hiện (từ giao diện chính Dashboard …)
26
Cloud Monitoring - Report
TASK II: API Library
How to find a right API for your Project
☺ Cách thứ 2 để vào trực tiếp “chợ API” từ Menu “API & Services
Trình tự các bước thực hiện (từ giao diện chính Dashboard …)
☺ Hiển thị danh mục các APIs thuộc “Category”: Maps, Databases
Ảnh chụp minh chứng theo mỗi loại “Category”
Google Earth Engine API, Places API, Geolocation API, Datastream API, Compute
Engine API, Cloud Run API, Cloud Healthcare API, Cloud Datastore API, Google
Drive API, YouTube Data API
27
Cloud Monitoring - Report
TASK III: API Enabling
Finding and Enabling APIs: Map JavaScript API, Cloud Storage API
and BigQuery API
☺ Trình tự các bước thực hiện (tính từ giao diện chính Dashboard …)
28
Cloud Monitoring - Report
TASK IV: Capping your API usage
☺ Select a API and “modify limit number of requests” for this API
Ảnh chụp minh chứng
☺ Mục đích chính của “Monitoring API usage” là gì trong việc quản lý Project
☺ Liệt kê bao nhiêu cách để truy cập vào tính năng quản lý API từ Google Cloud
☺ Trình tự các bước thực hiện (từ giao diện chính Dashboard …)
30