今日推荐英文原文：《How Software Talks to Other Software: APIs Explained for Humans》
今日推荐英文原文：《How Software Talks to Other Software: APIs Explained for Humans》作者：Dana Hooshmand
推荐理由：简单的解释 API 到底是什么
How Software Talks to Other Software: APIs Explained for Humans“Why does everyone keep saying APIs are important?” you say. “I thought I knew what they were, but now I’m not so sure.”
You’re not alone! Most people aren’t technical; but some make themselves seem technical by saying things like “APIs” and “protocol”. But even if you don’t code you can learn this too, and once you do, it’s like knowing the language of magic.
Spoiler: At the bottom, I’ll show how to use APIs without any code to do this very magic.
Don’t be scared. Here’s what APIs are.
An API is the way modern software communicates with other software, letting them work together just like we work together as humans.
Let’s consider the way we work as humans as a metaphor. There are two ways we communicate with each other: when we realise we NEED things and when something happens and we have to INFORM someone. Others too, because we’re not machines (well, most of us are not) and like to have jokey banter and occasionally airdrop memes to each other, but these are the transactional ways.
Here are some examples:
- “I need things”: “I am hiring some more staff next. How do I get them set up with laptops and company t-shirts and drink bottles? “You ask some people to do it, and they help you out.
- “I have to inform you of something”: Your boss asks you: “Every time you do an expense report, can you email (inform) me, so I don’t miss it?” Sure thing, you say.
There are two main kinds of APIs we use: REST APIs (aka RESTful ones, or ‘endpoints’), which wait around until you need something, and ‘triggers’ (also known as ‘webhooks’), which inform proactively
Example of a REST (‘need’) API: These are APIs that are waiting around to be asked something (RESTing, I think).
You go to Google Maps and click on ‘Home’. The app queries a series of APIs (who were waiting around to be asked… RESTing, I think) to find out
- From Google Maps: All the routing information and traffic times
- From Lyft/Uber: An estimate of the prices to get a ride
- From Yelp: Some well reviewed places to eat near home that are open
You pay for your coffee at some cafe using Square. Square says ‘yo this person just dropped $6 on a cappuccino’ to some survey software via a trigger. The survey software sends you an email asking you if it was worth listening to the barista’s edgy vinyl for 15 minutes after taking your money while he slowly worked through the queue.
Why APIs are important
When you find software that has a well-written API, you will know it will be easier and cheaper to use that software to build things, and that that software company is well-organized.
- APIs make it easier to connect applications, saving time and money (developer costs). If we have to integrate software (like, for example, payroll, HR and procurement software), we want to make sure the developers planned on their software being easy to connect with other people’s software. This includes them thinking about security standards. There’s LOTS of ways of providing a secure API and authenticating, and this is super critical to a huge company. (If a company that holds your SSN has an API, you want to be really sure they’re not going to get hacked.)
- Having a good API implies that the company is really structured and organized. A good API with good documentation is like meeting someone with really good filing and organization. It makes them seem trustworthy and un-chaotic. (Note to self: tidy desk before posting this.)
What API data looks like in practice
Good news! Modern software tries to use fairly human language, just with more structure around it. It looks like the following.
Note that you only need to know it looks like this and that it’s easy to read. You don’t need to know how to write it. There is some data in there, plus text and other stuff.
"title": "Webhooks example",
"title": "Thanks, Dana! What's it like where you live? Tell us in a few sentences.",
"title": "If you're OK with our city management following up if they have further questions, please give us your email address.",
The best part: How to use APIs to perform magic without code
There are three main ways: what engineers do (expensive; wait until two quarters from now), existing connections (convenient but limited, like Typeform automatically connects to Google Sheets), or cool things like Zapier and IFTTT. I’ll focus on Zapier, though IFTTT and other apps do similar things.
Zapier is a piece of software that takes inputs, processes them and produces outputs.
Here are some examples of how I have used them at work and personally
- At work: Every time a visitor checks into a center, create a ticket for them in a queue management system, and send them an SMS afterwards with a follow-up survey. (This saved about 3 minutes per interaction, which for us, added up to 5,000 hours a month).
- Personally: Every time I create a new blog post, make a marketing post and put it on Twitter, Facebook, LinkedIn and email it to every subscriber. (This saves me about 15 minutes each time it runs)
- In between work and personal: Every day at 8am, send me a picture of a motorcycle with a countdown timer to my last day at work saying how many days were remaining.