初学api测试_api初学者指南

初学api测试

If you’re a student studying Computer Science or someone who’s trying their luck getting into the software industry, one might often encounter the phrase API. API stands for Application Programming Interface. It is an integral part of software development. To understand APIs, let’s start with the last word in the acronym — Interface.

如果您是学习计算机科学的学生,或者是想进入软件行业的幸运者,那么可能经常会遇到API一词。 API代表应用程序编程接口 。 它是软件开发的组成部分。 为了理解API,让我们从首字母缩略词“ 接口”开始

什么是接口? (What is an Interface?)

An interface is a layer (or an abstraction) wherein most of the underlying functionality is removed from the eyes of the user, and provides a simple platform to the user to interact with the entity, such as a TV!

界面是一层层(或抽象层),其中大部分基本功能已从用户的眼中移开,并为用户提供了一个简单的平台来与实体互动,例如电视!

We use a TV remote to change the channels, control the volume or the brightness of our display. Here the TV remote acts as our interface to the TV. We, as the end user, can control all the functionalities of our idiot box using only the buttons present on the TV remote without even knowing HOW it is done.

我们使用电视遥控器更改频道,控制显示器的音量或亮度。 电视遥控器在这里充当我们与电视的接口。 作为最终用户,我们可以仅使用电视遥控器上的按钮来控制白痴盒子的所有功能,甚至不知道它是如何完成的。

Ever heard of the term GUI? A GUI — Graphical User Interface, provides an Interface which makes it easier for the user to operate a particular program.

有没有听说过GUI这个词? GUI —图形用户界面,提供了使用户更容易操作特定程序的界面

Similarly, for developers, most of the components are reusable, which are abstracted and accessed via an Interface, for Application Programming. Hence, the API.

同样,对于开发人员来说,大多数组件都是可重用的,这些组件可以通过接口抽象和访问,以进行应用程序编程 。 因此,API。

API简介 (Introduction to APIs)

APIs provide the required data and abstracts most of the implementation by the underlying code to the software developer, which saves a lot of time, developmental costs and in general, a lot of work, if done from scratch.

API提供了所需的数据,并通过底层代码向软件开发人员抽象了大多数实现,如果从头开始,则可以节省大量的时间,开发成本以及总体上的大量工作。

Today, it’s safe to assume that whenever we hear the word “API” it’s mostly a web-based API, but APIs constitute a much larger demographic. For example, if converting a string to uppercase, any programming language provides a method to achieve it. That’s APIs in action. We can do the same by manipulating in the low level bits, but by using APIs is much easier, faster and more convenient.

如今,可以安全地假设,每当我们听到“ API”一词时,它基本上都是基于Web的API,但是API构成了更大的受众。 例如,如果将字符串转换为大写,则任何编程语言都可以提供一种方法来实现。 这就是API的作用。 我们可以通过操作低级位来完成相同的操作,但是使用API​​更加容易,快捷和方便。

Likewise, Frameworks provide an API to developers for faster development for their applications. These APIs perform a ton of work for us, instead for the developer to reinvent the wheel. All we need to do is provide the required data to the framework API for it to work.

同样,框架为开发人员提供API,以加快其应用程序的开发速度。 这些API可以为我们完成大量工作,而不是让开发人员重新发明轮子。 我们需要做的就是向框架API提供所需的数据以使其正常工作。

基于Web的API (Web-based API)

As we all now know that APIs do a lot of work for us by abstracting a ton of things under the hood, as technology evolved, so did APIs.

现在我们都知道,随着技术的发展,API通过在幕后抽象出很多东西来为我们做很多工作,API也是如此。

With the advent of internet and more specifically cloud computing, more and more people started to send data through the internet. Likewise, many businesses and institutions started to provide their services through the internet using — APIs.

随着Internet的出现,尤其是云计算的出现,越来越多的人开始通过Internet发送数据。 同样,许多企业和机构也开始使用API​​通过互联网提供服务。

Say if a user wanted to find today’s weather, the user obviously doesn't have an inbuilt barometer in his phone or wires connected to the local weather station from his phone. The user can just use a weather app which uses the location from the user’s phone’s GPS and sends it to a remote web-based API which in turn responds with the current weather data to the user’s phone.

假设用户想查找今天的天气,则该用户显然没有手机内置的气压计,也没有从手机连接到本地气象站的电线。 用户可以只使用天气应用程序,该应用程序使用用户手机的GPS中的位置并将其发送到基于Web远程API ,该API依次以当前天气数据响应用户的手机。

Remote APIs are constructed by developers using several approaches. The most popular one is REST — Representational State Transfer. The APIs that utilise this approach are said to be RESTful.

远程API是开发人员使用几种方法构造的。 最受欢迎的一种是REST-代表性状态转移 。 利用这种方法的API被称为RESTful

REST API is so popular that if people refer to any API, they usually mean it as a RESTful one.

REST API非常流行,以至于人们引用任何API时,通常都将其称为RESTful。

To understand how one accesses data from a RESTful API, one needs to understand how computers talk with each other via internet.

要了解人们如何通过RESTful API访问数据,需要了解计算机如何通过Internet相互通信。

互联网 (The Internet)

There are different types of devices, desktops, smartphones, servers, gaming consoles etc, that are connected to the internet. One might wonder, how come a smart refrigerator in South Korea is able to talk and get data from a weather sensing station somewhere in the Hawaii through the internet? There must be some kind of common language, a rule or in geeky terms — a protocol.

连接到Internet的设备,台式机,智能手机,服务器,游戏机等有不同类型。 有人可能想知道,韩国的智能冰箱如何能够通过互联网从夏威夷某处的气象站进行对话并获取数据? 必须有某种通用语言,规则或怪异的术语- 协议。

Let me introduce you to the Hypertext Transfer Protocol or HTTP, in short. HTTP is the common protocol (or rule) where in all the devices no matter their underlying design, when connected to the internet, use it to communicate with each other in a way they could understand.

简而言之让我向您介绍超文本传输​​协议或HTTPHTTP是通用协议(或规则),在所有设备中,无论其基础设计是什么,当连接到Internet时, HTTP都以它们可以理解的方式相互通信。

In Hypertext Transfer Protocol, as the name suggests, transfers something called ‘Hypertext’.

顾名思义,在“ 超文本传输​​协议”中 ,传输称为“超文本”的内容。

For our reference, lets limit our understanding of a Hypertext as a document that contains some text and links that are displayed on a computer screen (or similar devices) which can be accessed by a user easily.

作为参考,让我们限制对超文本的理解,因为超文本是一个包含一些文本和链接的文档,这些文本和链接显示在计算机屏幕(或类似设备)上,用户可以轻松访问这些文本和链接。

This Hypertext is usually obtained by sending a request from a client (your computer) to a remote server (some other computer connected to the internet) which then responds with a Hypertext document containing the data.

通常,通过从客户端(您的计算机)向远程服务器(连接到互联网的其他计算机)发送请求来获得此超文本,然后该远程服务器将以包含数据的超文本文档作为响应。

An HTTP request should be accompanied by an HTTP verb — GET,POST,DELETE etc., usually by default it is GET. But again this blog isn’t about HTTP requests or computer networking, so for our reference, let’s assume GET is used to retrive the data from the server, POST is to send and DELETE is to send a request to delete data on the server.

HTTP请求应带有HTTP动词-GET,POST,DELETE等,通常默认情况下为GET。 但是,此博客还是与HTTP请求或计算机网络无关,因此,作为参考,我们假定GET用于从服务器中检索数据,POST用于发送,而DELETE用于发送删除服务器上数据的请求。

So coming back to how our RESTful APIs get data, a client(the smart refrigerator) requests a Resource (weather data) to the server (a very busy and lonely computer in Hawaii) and the server responds with the resource (weather data again). Also, the REST APIs are Stateless — No data of the transfer is stored anywhere between the client and the server.

因此,回到我们的RESTful API如何获取数据的方式,客户端(智能冰箱)向服务器(夏威夷的一台非常繁忙和孤独的计算机)请求资源 (天气数据),然后服务器以资源(再次是天气数据)进行响应。 此外,REST API是无状态的-客户端和服务器之间的任何位置均不存储任何传输数据。

现在,我们可以使用API​​做什么? (Okay now, what can we do with APIs?)

We can practically build any app for any purpose that we can think of!

实际上,我们可以出于我们可以想到的任何目的构建任何应用程序!

In the next blog, I’ll call one of these APIs to GET the data using several methods. Till then enjoy this comic:

在下一个博客中,我将调用这些API之一来使用几种方法来获取数据。 直到享受这部漫画:

Image for post
For more: https://theycantalk.com/
有关更多信息: https : //theycantalk.com/

翻译自: https://medium.com/@harish.pillarisetti/a-beginners-guide-to-apis-19bc270c74b9

初学api测试

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值