rest api
API stands for Application Programming Interface, and it’s an umbrella term that identifies different things.
API代表应用程序编程接口,它是一个笼统的术语,用于标识不同的事物。
We saw how the browser can offer some APIs, in the form of functions available to us.
我们了解了浏览器如何以可用功能的形式提供一些API。
We saw how Node.js offers us a programming API with its default modules.
我们看到了Node.js如何为我们提供带有默认模块的编程API。
API also means another thing: creating a service that exposes some specific functionality, provided through a server that can be accessed by multiple clients.
API也意味着另一件事:创建一个服务,该服务公开一些特定功能,该功能是通过服务器提供的,可以由多个客户端访问。
Broadly speaking, we currently have 2 categories of APIs: REST APIs and GraphQL APIs.
从广义上讲,我们目前有2类API:REST API和GraphQL API。
Other kinds of API paradigms exist, like SOAP for example, but they are not very popular in the JavaScript world.
存在其他种类的API范例,例如SOAP,但是它们在JavaScript世界中并不十分流行。
In this post we’ll talk about REST APIs.
在本文中,我们将讨论REST API。
终点 (Endpoints)
In a REST API, we create a number of endpoints that a client can access.
在REST API中,我们创建了许多客户端可以访问的端点 。
Say we want to expose a list of people. We can create an endpoint that will respond to the /people
route.
假设我们要公开人员名单。 我们可以创建一个端点来响应/people
路线 。
If our service listens on the domain test.com
, we’d have the test.com/people
URL.
如果我们的服务在域test.com
上进行侦听,则将具有test.com/people
URL。
This endpoint will provide data in any format, but generally we use JSON, a handy text-based format used to communicate data between two services.
该端点将以任何格式提供数据,但是通常我们使用JSON (一种方便的基于文本的格式,用于在两个服务之间传递数据)。
This /people
endpoint can provide a list of names of people, and an id
for each person. This might be the id
that we use to store them in the database, for example.
/people
端点可以提供人员