iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 3
0
AI & Data

Machine Learning Study Jam 2020系列 第 3

Introduction to APIs in Google

Okay... so there's a funny story...

As I registered in this ML Study Jam, they gave me "credits" to access each lesson in Machine Learning APIs course. To complete the course, I need to answer all the quizes in each lesson with the access granted. Even funnier is these "credits" only valid in THIS ONE MONTH.

To make the story short, we need to skip the 2 hands-on labs as mentioned in the first article and jump right into the first lesson of Machine Learning APIs - Introduction to APIs in Google

Life is full of surprises right?! /images/emoticon/emoticon01.gif

No more wasting time~ Let's start!


In this lesson, you will learn:

  • Google APIs
  • API architecture
  • HTTP protocol and request methods
  • Endpoints
  • REST (Representational State Transfer) and RESTful APIs
  • JSON (JavaScript Object Notation)
  • API authentication services

Google APIs

An API (Application Programming Interface) is a software program that gives developers access to computing resources and data.

Google offers APIs that can be applied to many different fields and sectors. APIs are often used in web development, machine learning, data science, and system administration workflows.


API architecture: Client-server model

The internet is the standard communication channel that APIs use to transmit requests and responses between programs. The client-server model is the underlying architecture that web-based APIs use for exchanging information.

This is a visual representation of the client-server model:
https://ithelp.ithome.com.tw/upload/images/20200916/20130054M5yvTBBPWN.png

The client is a computing device (e.g. a smartphone, laptop, etc.) that makes a request for some computing resource or data. The client's request needs to be formatted in the agreed upon protocol.

The server has data and/or computing resources stored on it. Its job is to interpret and fulfill a client's request.


HTTP protocol and request methods

Since APIs use the web as a communication channel, many of them adhere to the HTTP protocol, which specifies rules and methods for data exchange between clients and servers over the internet.

APIs that utilize the HTTP protocol use HTTP request methods for transmitting client requests to servers. The most commonly used HTTP request methods are GET, POST, PUT, and DELETE.

GET -> is used by a client to fetch data from a server. If the requested resource is found on the server, it will then be sent back to the client.

PUT -> replaces existing data or creates data if it does not exist. If you use PUT many times, it will have no effect — there will only be one copy of the dataset on the server.

POST -> is used primarily to create new resources. Using POST many times will add data in multiple places on the server. It is recommended to use PUT to update resources and POST to create new resources.

DELETE -> removes data or resources specified by the client on a server.


Endpoints

Endpoints are access points to data or computing resources hosted on a server and they take the form of an HTTP URI. Endpoints are added to an API's base URL (e.g. http://example.com) to create a path to a specific resource or container of resources.

The following are some examples of endpoints:

You can add query strings to endpoints (e.g. http://example.com/students/?id=1) to pass in variables that may be needed to complete an API's request.


RESTful APIs

APIs that utilize the HTTP protocol, request methods, and endpoints are referred to as RESTful APIs. REST (Representational State Transfer) is an architectural style that prescribes standards for web-based communication.

REST is the most widely used framework for APIs. In 2010, about 74% of public network APIs were HTTP REST APIs.

Besides query strings, RESTful APIs can also use the following fields in their requests:

  • Headers -> parameters that detail the HTTP request itself.
  • Body -> data that a client wants to send to a server.

The body is written in the JSON or XML data formatting language.


API Data Formats (JSON)

JSON(JavaScript Object Notation) has surpassed XML in RESTful API use largely because JSON is lightweight, easier to read, and faster to parse.

JSON supports the following data types:

  • Numbers -> all types — no distinction between integers and floating point values.
  • Strings -> text enclosed in quotes.
  • Booleans -> True or False values.
  • Arrays -> a list of elements grouped by similar type.
  • Null -> an "empty" value.

A JSON object uses curly braces { } to group data that's arranged in key-value pairs. Commas separate the key-value pairs stored in an object.
Ex:

{
	"teacher": "Julie",
	"students": ["Alice", "John", "Tom", "Kent"],
	"class": "3-A",
    "number-of-students-sick": 10,
    "is-ready-to-start-lesson": false
}

Authentication and Authorization

  • Authentication -> the process of determining a client's identity.
  • Authorization -> the process of determining what permissions an authenticated client has for a set of resources.

In a simple way of saying, authentication identifies who you are, and authorization determines what you can do.

Google APIs use these 3 types of authentication/authorization services:

  • API Keys -> secret tokens that usually come in the form of an encrypted string.
  • OAuth -> are similar to API keys in their format, but they are more secure and can be linked to user accounts or identities.
  • Service accounts -> a special type of Google account that belongs to your application or a virtual machine (VM) instead of to an individual end user.

Wow! Didn't expect we have so many things to introduce today. /images/emoticon/emoticon13.gif

Really appreciate you finish reading this long article and hope you get more familiar with APIs. (Or probably it's too easy for you if you are already very proficient at it XD


上一篇
A Tour of Qwiklabs and Google Cloud
下一篇
Extract, Analyze, and Translate Text from Images with the Cloud ML APIs
系列文
Machine Learning Study Jam 202012
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言