SDK和API区别

B站视频:https://www.bilibili.com/video/BV1dA411K7Ps/?spm_id_from=333.337.search-card.all.click&vd_source=85701dd8aeeae2aaac0299ea796f19bb

 

假设你在开发一款移动端兽医诊所应用

Let's say you're developing a mobile app for a veterinarian clinic

想法是该移动端应用

and the idea is for this mobile app to actually  

当宠物走入诊所允许接待员为其拍照

allow a receptionistto take a picture of a pet as it enters the clinic

应用会自动与视觉服务进行通信,都运行在云端

and the app will communicate with a visual recognition service, that's running on the cloud

服务器端想法就是,返回宠物名字,传回它们的文档

And the idea is for the service to return the pet's name and bring up their file

如何在移动和云服务端 之间通信呢?

How do we communicate between the mobile app and this cloud-based service

这就要用到API和SDK了

Well, that's where APIs and SDKs come in

从API开始谈起

Let's get started by talking about APIs

一、什么是API?What's an API

1、API概念

首先,API全部与通信有关

First of all, APIs are all about communication

应用或服务端有一组定义和协议,用于和其他应用或服务对话

There are a set of definitions and protocols for apps or services to talk to other apps or services

你可以将其视为一种桥梁,在应用和云视觉识别服务间

So you can kind of think of them like a bridge between your app and say this cloud-based visual recognition service

那么API到底代表什么,应用程序接口的缩写

So what does 'API' standfor anyway. Well, it's Application Programming Interface

哪些方面又使API有用呢?

And what are some of the aspects of APIs that make them useful

1)它们都是关于通信的

They're all about communication

服务器和其他服务器间,应用和其他应用间,彼此交流的方式

So communicating between a service and an other service, an app and another app, it's how they talk to each other

2)其次,它们都是关于抽象的

Next, they're all about abstraction

抽象是什么意思

What does 'abstraction' mean

在VR服务中,在云中,可能运行着成千上万行代码

So, inside the VR service up in the cloud, there's probably potentially thousands of lines of code running up there 

作为移动端开发的你,你不用去考虑,我调用服务中的哪个方法可以得到宠物名字

And you as a developer of a 010mobile app, you don't want to have to worry about which method in this service do I call to get the pet's name

API的作用就是,它可以抽象出所有复杂逻辑,只需要考虑自己需要的即可,简化了过程

So,what an API does is it abstracts away all that complicated logic,so you just have to worry about getting just the data you need.It simplifies the process.

3)API是标准化 (REST)

Third, APIs are standardized

有行业标准来说明如何定义API

Meaning, there's industry-defined standards for how to define an API

有很多流行的API格式

and there's a few formats that are popular for APIs

你可能听过SOAP,GraphQL, REST, REST表示表现层状态转换

You may have heard of SOAP GraphQL or REST,which fun fact stands for Representational State Transfer

正是本视频所关注的

and that's waht we'll focus on for this video

2、API的构成要素是什么

So,what are some of the building blocks of APIs

1)发送请求 make up a request

首先,要发送数据

First of all, to actually send data or send what's called a request

从移动端应用到云端的VR服务

from the mobile app to the VR service on the cloud

你需要做些不同事情

you need to have a few different pieces

操作 Operation

对于REST API调用请求,你需要有个所谓的“操作”

So, for a REST API call request, you need to have what's called an operation

可能是HTTP方法,像post,put,get,delete

So this could be HTTP methods,like POST, PUT, GET, DELETE

本例就是post方法

In this case it would be a POST method

向服务器发送一个请求

because you're sending a request over to the service

可能是文件名字,包含拍摄的宠物图像

which might include something like maybe the file name of the image you took of the pet

参数 Parametes

接下来是参数,这是可选的

Next, would be parameters,this is optional

本例就有可能是图像的文件夹名,也许是cat,jpeg,拍的一张喵片

In this case might be the file name of the image you took. So maybe cat.jpeg,if it's a cat that you took a picture of 

结点 End point

最后就是结点,就是图像识别服务的UR,你尝试交互的

Finally, would be the end point.So, that's the URL basically of the visual recognition service that you're trying to talk to

可能是url / analyze

So, maybe that's, you know, it's some URL-slash-analyze

这就是你的请求对吧

Great, so that's your request, right

2)响应 Response

收到REST API返回的响应,从视觉识别服务返回的长什么样子呢?

What might a REST API response call that you receive back from the visual recognition service look like

基本上就是某种原始数据,也许是JSON

Typically it's some form of raw data,maybe JSON

响应就像这样,这种排序的数据对象,包含结果、类型就是cat、也许名字叫Mittens

So, a response might look something like this. So, you have sort of this data object, that might include the result,the type which is a cat, and maybe the name which in this case may be Mittens

这就是API的基本组成部分

Great, so that's sort of the building blocks of what an API is 

作为开发人员,如何在代码中调用API呢

As a developer though, how do you actually call an API in your code

你不想去担心设置请求的这些操作,参数,结点,以及处理原始JSON对象

You don't want to have to worry about setting up your request with all thest building blocks of operations,parameters,end points,and dealing with raw JSON objects

这就是SDK登场的地方

So that's where SDKs come in and really shine

二、什么是SDK?What's an SDK

让我们谈谈SDK,它表示什么

So, let's talk about SDKs, what does that stand for

软件开发工具包的缩写,很直接对吧

Well, it is Software Development Kit. Pretty straight forward,right?

可以把SDK想成工具箱,其中的工具(代码)会为你去调用API

So, SDKs, you can really think of like a toolbox of tools, or code that actually call APIs for you

你可能精通一门编程语言

So you may be specialized in one programming language over the other

在很多语言中都有SDK,也许是JAVA中的SDK,或者Node.js,也许GO,又或者Python

you know, there's SDKs in a variety of languages.So, there's maybe an SDKin Java, in Node,maybe GO, or Python

无论你擅长哪门语言,都有适合你的SDK

whichever language that is your specialty, there's probably an SDK for you

回到我们这里的例子,此例子中SDK长什么样

So, back to our example over here. what might an SDK look like in this example

要用SDK,将SDK工具箱放到移动端这里

So, with an SDK, let's go ahead and put our little SDK toolbox within the mobile app

本例由于是移动端,标注使用Java SDK

and for this case since it's a mobile app, say we'll use the Java SDK

在这个Java SDK中,不用通过手动构建模块配置这些请求

So, in this Java SDK, rather than having to configure your request manually with all these building blocks

你可能实际就调用一个方法,也许叫获得结果

you might actually call just a method,that's maybe called Idont know Get Result

就会调用不同的构建块:操作、参数、请求

that will actually call these various building blocks: the operation, the parameters, and the request for you

通过代码为你提供API请求

it'll make it for you and it'll make that API request for you with code

你会得到响应,也不一定是JSON对象,可能是一些代码,也许是Java本地对象模型,叫做分析响应对象

In response, you'll get a response,but it won't be necessarily a JSON object, it might be some code, maybe a native model object in Java, called an Analyze Respnse Object

代码就像这样,你有ARO

So, the code might look something like this. So, you have an Analyze Response Object

你调用图像识别分析和返回结果方法

that you call the 'Visual Recognition Analyze and Get Results' method

你传入cat.jpeg参数,就是文件的名字

You pass in a parameter which is 'cat.jpeg',which is the name of the file

发送给图像识别服务

that you sent over the visual recognition service

在响应中,可以在移动端设置一个标签,即Mittens

and in response, you can actually go ahead and set a label in your mobile app, to be Mittens

这就是Java中的ARO接收到的数据,通过你的SDK,就会看到Mittens走进了诊室

So, that's the data you received in the form of an analyze response model object in Java via your SDK and you're able to see Mittens has entered the building

希望以上总结,API是什么,SDK是什么,都有何用途

So,hopefully, this kind od summarizes, what's an API, what's an SDK, what are both used for

以及它们如何成为你云应用开发工具箱中,最基础的工具

and how they are truly fundamental tools in your cloud app development toolbox

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZYYzyy1993

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值