开源日报 每天推荐一个 GitHub 优质开源项目和一篇精选英文科技或编程文章原文,坚持阅读《开源日报》,保持每日学习的好习惯。
今日推荐开源项目:《xswl dad-jokes》
今日推荐英文原文:《How Software Talks to Other Software: APIs Explained for Humans》

今日推荐开源项目:《xswl dad-jokes》传送门:GitHub链接
推荐理由:一个……非常有意思的笑话合集。这里面的笑话都是与编程有关的,而且正在不断持续更新中,兴许时常来看看它们调节一下生活的节奏也是不错的选择。
今日推荐英文原文:《How Software Talks to Other Software: APIs Explained for Humans》作者:Dana Hooshmand
原文链接:https://medium.com/@hoosh/how-software-talks-to-other-software-apis-explained-for-humans-72e9f9c44be4
推荐理由:简单的解释 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.
APIs automate those ‘need’ and ‘inform’ situations.

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
Example of a Trigger (‘inform’) API: These all involve a listener, which is sitting around waiting for it to be told something.

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.
  1. 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.)‌‌
  2. 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.
{ 
  "event_id": "12345", 
  "event_type": "form_response", 
  "response": 
  {
    "form_id": "lT4Z3j",
    "submitted_at": "2018-01-18T18:17:02Z",
    "definition": 
    { 
      "title": "Webhooks example",
      "fields": [ 
      { 
        "id": "DlXFaesGBpoF",
        "title": "Thanks, Dana! What's it like where you live? Tell us in a few sentences.",
        "type": "long_text" 
      }, {
        "id": "SMEUb7VJz92Q",
        "title": "If you're OK with our city management following up if they have further questions, please give us your email address.",
        "type": "email" 
      }, {...

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.
I’ll write a follow-up post about some of the cooler things you can do via Zapier.
下载开源日报APP:https://openingsource.org/2579/
加入我们:https://openingsource.org/about/join/
关注我们:https://openingsource.org/about/love/