Skip to Content
Node与Express开发(第2版)
book

Node与Express开发(第2版)

by Ethan Brown
June 2021
Intermediate to advanced
290 pages
9h 21m
Chinese
Posts & Telecom Press
Content preview from Node与Express开发(第2版)
REST API
和
JSON
|
161
学语言的形式,但其本质无非就是客户端和服务器端之间的无状态连接。
REST
的正式定
义也指出,服务既可以被缓存,也可以被分层(也就是说,当你在使用一个
REST
API
时,
在它之下可能还有另外的
REST
API
)。
从现实出发,由于
HTTP
本身的限制
,创造一个不是
RESTful
的
API
反倒很困难,比方说
你还要费很大劲去建立状态。因此,我们的
REST
API
的工作非常省事。
15.1
 
JSON
和
XML
要提供一套
API
,最重要的是双方要有“共同语言”。沟通方式的一部分已经规定好了,
就是必须使用
HTTP
方法来跟服务器通信
。但在此之后,可以自由选择要使用什么样的
数据表示方式。过去,
XML
是主流选择
,现在,它仍是重要的标记语言。尽管
XML
不
算特别复杂,但
Douglas
Crockford
还是觉得某种更轻量的东西很有必要,于是
JavaScript
Object Notation
(
JSON
)就诞生了
。它除了对
JavaScript
很友好之外(但并不意味着它是
JavaScript
专有的,
对任何语言它都是易于解析的格式),还有通常而言更易于手写的优势。
对大多数应用而言,我更偏好
JSON
而不是
XML
,因为
JSON
对
JavaScript
有更好的支
持,而且它的格式更简单、更紧凑。我建议主要关注
JSON
,仅当有系统要求用
XML
跟你
的应用通信时才提供
XML
。
15.2
 我们的
API
在开始实行
API
之前需要先规划好它。除了列出度假产品和订阅产品“上市”通知以外,
还需要增加一个“删除度假产品”的端点 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

面向对象的思考过程(原书第5版)

面向对象的思考过程(原书第5版)

马特 魏斯费尔德
精通模块化JavaScript

精通模块化JavaScript

Nicolás Bevacqua

Publisher Resources

ISBN: 9787115565099