应用程序编程接口大全_应用程序编程接口101

应用程序编程接口大全

Do apps like Uber, Pokémon Go and Zomato build their own maps to show where available cars are, help the user find wild Pokémon, or display nearby restaurants. Do these apps need to spend thousands of person-hours making their own maps? We all know, that the answer is no. They embed a Google Map in their app. Uber app draws the route you’ll take on a Google Map and calculates the approximate time it’ll take to get there.

诸如Uber,PokémonGo和Zomato之类的应用程序会构建自己的地图以显示可用车的位置,帮助用户查找野生的Pokémon或显示附近的餐馆。 这些应用是否需要花费数千个人工时制作自己的地图? 众所周知,答案是否定的。 他们在自己的应用程序中嵌入了Google地图。 Uber应用程式会在Google Map上绘制您要走的路线,并计算到达那里所需的大概时间。

Google lets you include a small snippet of code in your app to draw a Google Map, and it provides other snippets of code to let you draw on the maps, calculate driving directions between points on the map, and even find out the speed limit for a particular road. All of these tools are cheap or even free. These tools are big win for developers; they can use the technology which took Google years to perfect with just a small amount of code. There’s no need to reinvent the wheel!

Google允许您在应用程序中包含一小段代码以绘制Google Map,并提供其他代码段以使您可以在地图上绘制,计算地图上各点之间的行驶方向,甚至可以找到速度限制一条特定的道路。 所有这些工具都很便宜,甚至免费。 这些工具对开发人员来说是巨大的胜利。 他们只需使用少量代码就可以使用Google花费了数年时间完善的技术。 无需重新发明轮子!

These snippets of code that let you borrow another app’s functionality or data are called APIs, or Application Programming Interfaces. In short, APIs let apps talk to each other.

这些可让您借用其他应用程序功能或数据的代码段称为API或应用程序编程接口。 简而言之,API使应用程序可以相互通信。

那么,什么是API? 就像菜单。 (So, what is an API? It’s like a Menu.)

In another analogy, you’re a program and the restaurants are programs that you want to interact with. To receive what you want (food) from the other program (restaurant), you need to make a request (place an order) in a specific way (defined by the menu).

另一个比喻,您是一个程序,而餐厅是您要与之交互的程序。 要从其他程序(餐厅)接收想要的东西(食物),您需要以特定方式(由菜单定义)发出请求(下订单)。

APIs are like menus. Menus define a list of dishes and, when someone orders one of those dishes, the restaurant does a bunch of stuff and then sends the requested dish back. APIs define a list of commands and, when a program uses one of those commands, the other program does a bunch of stuff and then sends back what was requested by that command (usually some kind of data).

API就像菜单一样。 菜单定义了菜肴列表,当有人订购其中一种菜肴时,餐厅会做很多事情,然后将请求的菜肴发回。 API定义了一个命令列表,当一个程序使用这些命令中的一个时,另一个程序会执行很多操作,然后将该命令所请求的内容(通常是某种数据)发送回去。

It’s important to note that food ordering analogy isn’t perfect. When you order food, there are many variations you could use to get the same result. But programs aren’t as smart and flexible as humans. When making a request to another program, the request has to be formatted in a very specific way.

重要的是要注意,食品订购类比并不完美。 当您订购食物时,可以使用多种变体来获得相同的结果。 但是程序不像人类那样聪明和灵活。 向另一个程序发出请求时,必须以非常特定的方式格式化该请求。

If restaurants were like programs, saying “House Burger, medium-rare, no pickles, replace the fries with coleslaw” would get you your food but saying “may I please have the House Burger cooked medium-rare with coleslaw instead of fries and no pickles on the burger” would not. The restaurant wouldn’t understand what you’re asking because the request isn’t formatted correctly.

如果餐厅像节目一样,说“ House Burger,中度稀少,没有咸菜,用凉拌卷心菜代替薯条”会为您带来食物,但会说“请我让House Burger用凉拌卷心菜而不是薯条煮中等稀饭,在汉堡上腌制”不会。 餐厅无法理解您的要求,因为请求的格式不正确。

So APIs define a list of commands as well as the necessary format of those commands. When a company releases an API for their software, it means that they’ve basically told everyone: here is what you can get from our program and here is exactly how you have to ask to get it.

因此,API定义了命令列表以及这些命令的必要格式。 当公司为他们的软件发布API时,这意味着他们已经基本告诉所有人:这是您可以从我们的程序中获得的,这正是您要求获得它的方式。

API类型 (Types of APIs)

There are three main kinds of APIs:

API有三种主要类型:

The first kind of API lets one app ask another specialized app to solve a particular problem, like calculating driving directions, sending text messages, or translating sentences. It’s like how you could call a plumber or carpenter to fix problems around your house instead of trying to do it yourself. Here’s an example: apps like Uber can use PayPal’s Braintree API, which lets anyone use PayPal’s algorithm for processing credit card payments with just a few lines of code. It’s pain to write code yourself that sends emails or text messages — so when apps like Venmo need to send you confirmation emails or texts, they can just use a specialised API. And any app that lets you log in via Facebook or Google uses those websites’ APIs for verifying someone’s identity.

第一种API可让一个应用程序要求另一个专门的应用程序解决特定问题,例如计算行车路线,发送短信或翻译句子。 这就像您可以打电话给水管工或木匠来解决房屋周围的问题,而不是自己尝试解决。 这是一个示例:Uber等应用程序可以使用PayPal的Braintree API,该应用程序使任何人都可以使用PayPal的算法通过几行代码来处理信用卡付款。 自己编写发送电子邮件或短信的代码很痛苦—因此,当Venmo之类的应用需要向您发送确认电子邮件或短信时,他们只能使用专门的API。 任何允许您通过Facebook或Google登录的应用程序都使用这些网站的API来验证某人的身份。

The second type of API lets one app ask another app to hand over some interesting information, such as sports scores, recent Tweets, or today’s weather. It’s like calling the front desk at a hotel to learn which museums and restaurants they recommend. ESPN offers an API that lets you get rosters for every major-league sports team and scores for every game. New York’s subway system lets you track where trains are and predict when the next train will arrive at a station. And don’t worry, there’s even an API to get random images of cats.

第二种API使一个应用程序可以要求另一个应用程序提供一些有趣的信息,例如运动比分,最近的推文或今天的天气。 这就像给酒店的前台打电话,以了解他们推荐哪些博物馆和餐厅。 ESPN提供了一个API,可让您获得每个主要联赛运动队的花名册和每场比赛的得分。 纽约的地铁系统可让您跟踪火车的位置,并预测下一趟火车何时到达车站。 不用担心,甚至还有一个API可以获取猫的随机图像。

The final kind of APIs, lets developers access features of the device itself. Snapchat taps into your phone Camera’s API to zoom, focus, and snap photos. Google Maps itself uses your phone’s Geolocation API to figure out where in the world you are. Your phone even has sensors called accelerometers and gyroscopes, which fitness apps (and Pokémon Go) use to determine in which direction you’re walking and how fast you’re moving.

最后一种API 使开发人员可以访问设备本身的功能。 Snapchat可以利用手机相机的API来缩放,对焦和捕捉照片。 Google Maps本身使用手机的Geolocation API来确定您的位置。 您的手机甚至还具有称为加速度计和陀螺仪的传感器,健身应用程序(和PokémonGo)可使用这些传感器来确定您的行进方向和行进速度。

It’s worth noting that APIs aren’t perfect. Using an API makes app developers’ lives easier, but it also makes their apps dependent on the API. If PayPal’s Braintree payment API somehow stopped working, Uber would be unable to process payments — not great for their business. Still, a specialized company’s API will likely be more reliable than any similar feature that a non-specialist company could make themselves.

值得注意的是,API并不完美。 使用API​​可以简化应用程序开发人员的生活,但也可以使其应用程序依赖于API。 如果贝宝(PayPal)的Braintree付款API某种程度上停止工作,那么Uber将无法处理付款-这对他们的业务不利。 尽管如此,一家专业公司的API可能会比非专业公司自己制造的任何类似功能更可靠。

它们如何连接? (How are they connected?)

Let’s imagine that you are building an e-commerce application that takes orders from customers, verifies inventory and available credit, and ships them. The application consists of several components including the user interface, along with some backend services for checking credit, maintaining inventory and shipping orders.

假设您正在构建一个电子商务应用程序,该应用程序将接收来自客户的订单,验证库存和可用信贷,然后发货。 该应用程序由多个组件组成,包括用户界面以及一些用于检查信用,维护库存和运输订单的后端服务。

APIs and UI let you connect to the multiple backhand services which are built on these Mircroservices architecture (described in previous post).

API和UI使您可以连接到基于这些Mircroservices体系结构构建的多个反手服务(在上一篇文章中进行了介绍)。

Image for post
Software Architecture
软件架构

Nimish Nama, IIM Calcutta (2019–21)

Nimish Nama,IIM加尔各答(2019-21)

翻译自: https://medium.com/tech-trek-for-rookies/application-programming-interface-101-43506fcd09a8

应用程序编程接口大全

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值