假设您正在开发一个Web应用程序,并且您决定将功能与应用程序的表示分离,因为它提供了更大的自由度.
You create an API and let others implement their own front-ends over it as well. What you just did here is implement an SOA methodology, i.e. using web-services.
Web服务使功能构建块可以通过标准访问
独立于平台和编程语言的互联网协议.
因此,您需要在后端(web服务)和前端(使用数据)之间设计一种交换机制,前者处理和生成有用的内容,后者可以是任何内容.(web、移动或桌面应用程序,或其他web服务).这里唯一的限制是前端和后端必须"讲"相同的"语言".
That's where SOAP and REST come in.
They are standard ways you'd pick communicate with the web-service.
SOAP:
SOAP internally uses XML to send data back and forth. SOAP messages have rigid structure and the response XML then needs to be parsed.
WSDL is a specification of what requests can be made, with which parameters, and what they will return. It is a complete specification of your API.
REST:
休息是一个设计概念.
万维网代表了系统的最大实现
符合睡觉建筑风格.
It isn't as rigid as SOAP. RESTful web-services use standard URIs and methods to make calls to the webservice. When you request a URI, it returns the representation of an object, that you can then perform operations upon (e.g. GET, PUT, POST, DELETE). You are not limited to picking XML to represent data, you could pick anything really (JSON included)
Flickr的REST API更进一步,还允许您返回图像.
JSON和XML在功能上是等效的,是常见的 Select .还有一些基于RPC的框架,比如基于Protobufs的GRPC和Apache Thrift,可以用于API生产者和消费者之间的通信.web API最常用的格式是JSON,因为它在每种语言中都易于使用和解析.