Proper screening difference and the link between API & REST API & RESTful API & Web Service

API to see what you think of? Is the interface, third-party call, or API documentation? At first glance you might think this is too familiar, this is not a system develop daily series it? But you think about it, you will find the concept of API in your mind is so vague. How do you pass the search engines API, you will see a message like this: API - Application Programming Interface (Application Programming Interface), which is too abstract. Next, I will combine some of the lessons learned in development, with popular way to talk API, connections and differences between REST API, RESTful API Web Service as well as these four.

1, API 与 REST API

What is the API here quoting Wikipedia definition given by:? Application programming interface (English: A pplication P rogramming the I nterface, abbreviation: API ; also known as Application Programming Interface ) software system is the convergence of the different components of the agreement. This definition of the API is too broad and abstract, and popular speakers, API is a piece of an application with another application for a mutual "exchange" approach (agreement). In the Web application development, API is one of the main ways we retrieve the data through the network, API documentation, a list of URL will inform you retrieve data, query parameters, request method and response status, which aims to reduce the difficulty of Web application development shared data (text, audio, video, pictures, etc.) between two applications, while shielding the internal implementation details of the complex.

REST is Representational State Transfer acronym, literal translation is: Transferred state. REST API is a set of on how to build a Web application framework API rules, standards or guidance, or REST API API is to follow the principle of an architectural style. REST is specifically designed for Web applications, and its purpose is to reduce the complexity of development and improve the scalability of the system. The following are some basic needs met or conditions and principles to follow when designing REST-style architecture:

  • 1, in REST architecture, Web in all things (text, audio, video, images, links) can be abstracted into a unified resource (resource)
  • 2, in the REST framework, each resource has a corresponding unique resource identifier (resource identifier), when the status of the resource changes, the resource identifier does not change
  • 3, in REST architecture, all operations are stateless. REST architecture to follow the CRUD principle, all resources can complete the corresponding operation by GET, POST, PUT and DELETE four behavior.
  • 4, can be cached (optional), in REST architecture requires cache to effectively deal with large quantities of request
  • 5, consistent interfaces

Now, to understand the basic concepts and API REST API, that what similarities and differences between the two? If you follow a set of mathematical concepts to explain the connections and differences between the API and REST API, API is a superset of the REST API, REST API is a subset of the API; All REST API is API, but not all of the API are It is a REST API. More popular explanation is: all men are human beings, but not all of them are men.

2, REST API 与 RESTful API

In the first section, to understand what is REST API, the next talk similarities and differences between REST API and RESTful API. Many beginners is easy to equate these two, that the RESTful API is REST API, it literally could be a simple to understand, and when you go in-depth understanding of the nature of both, you will find that it is not. REST API is a Web API design specifications or guidelines, and RESTful API is a specific implementation of this principle in architecture design or specification. In other words, RESTful API is an informal way to implement the REST API, because there are many ways to achieve REST API, RESTful API is only one, and did not fully meet all the design principles of the REST API, each developer in the realization of the REST architecture the focus will be when there is a difference.

Many beginners will easily REST API and concepts both RESTful API confused, I think, just look at the literal meaning, but not concerned about the meaning of their own (as recognized in the same text, there being read, read endless middle, taken out of context). It's like a lot of people will equate to a woman transsexual, transgender facial appearance may look like women, but transgender people can not have children, it just meets the definition of a condition most women (to achieve), but essentially not woman.

Next, a simple example in order to deepen the understanding of the REST API and RESTful API. We will be given an executive CURD operations RESTful API design cases:

Description: resource-generation refers to the name of a resource, when possible student (student), teacher (teacher), book (books), etc., commonly used term to represent; {id} refers to the generation of a unique identifier for a resource ( resource identifier)

Here is an example of a small, student management, for example, design student management API. Student resources including ID, name and lessons learned information, student resources information is as follows:

Now, we need to save student data to the database, and then execute the query, modify and delete student data. User management API calls API students are as follows:

Speaking in front of the content, API shared data resources, while shielding the internal implementation, API users (clients) are concerned about the resources (read data), do not need to understand the internal structure of the API; API provider (server ) only concerned with its own internal implementation, rather than the relationship between API user (client) state. In order to deepen the understanding of this concept, students are given below internal management API implementation example:

Description:

Spring MVC-based sample code for implementation.

When addition to the content, you can also filter the query data provided by way of key-value pairs, such as access to all student data, student data just want to get sex as female, it can be done this way:

[GET] http://www.example.com/students?gender=female
复制代码

Tip: If you have to API data filtering function, the corresponding server-side API implementation code also needs to be adjusted.

In the previous sections, we mentioned the RESTful API is an informal specification implementations or the REST API. Why do you say? Because the design RESTful API, we can complete the operation by GET CURD way, can also be created by DELETE behavior of resources, modify resources by the POST behavior, its implementation is not strict or not strict accordance with the REST API constraints proposed to carry out. So RESTful API is an informal way to implement the REST API .

3, REST and Web Service

3-1, what is the Web Service?

The World Wide Web Consortium (W3C) said, Web Service can provide a standard method of interoperability between different software applications running on various platforms and / or frameworks. Features Web Service is to have good interoperability and scalability, as well as the use of XML and can be described program processing. They may be loosely coupled manner to achieve a combination of different services complex operations. The program provides a simple service can interact with each other to provide sophisticated value-added services.

Between the two major Web Service to communicate, as we know SOA (Service Oriented Architecture) via HTTP network protocol mainly depends on the XML-RPC and SOAP (Simple Object Access Protocol, Simple Object Access Protocol).

Tip: Never SOA (Service Oriented Architecture) and SOAP (Simple Object Access Protocol) confused, the former is a form of architecture, which is a data exchange protocol.

A simple example: Suppose a Web Service A provided by other applications to allow user information acquired URL features: [the GET] www.abc.com/{id}. id is the user's ... nothing to do, as long as they parse the returned XML document A service can be. Thus, exchange of data between the application program can not depend on the specific language and environment. This is like in different countries, different languages, as long as they know the grammatical structure of the language of each other, two people can communicate.

The advantages of 3-2, Web Service's

Use Web Service has several advantages as follows:

  • 1. Interoperability: Web Service allows communication between applications, data exchange and sharing services.
  • 2. Availability: Web Service functionality can find simple information from complex computational algorithms.
  • 3, reusability: Web Service can be combined with each other, in order to provide more complex services, because of its interoperability features, you can easily reuse Web Service components other services, increasing the reuse services.
  • 4, easy to deploy: Web Service can be deployed in the container based on Internet standards, as Apache, Axis2, so as to provide HTTP or WSDL (Web Service Definition Language) driven service.
  • 5, low cost: Web Service is deployed through packaged into a Web service component, thereby reducing the cost to use.

3-3, Web Service type

Currently, Web Service has two main schools:

  • 1, Service SOAP-based Web: SOAP (Simple Object Access Protocol) is an XML-based protocol for accessing Web Service. Its interface described in a machine-processable format called WSDL (Web Services Definition Language) document. To describe the Web Service by using a standard XML document in an XML file, an interface with detailed information, such as message format, transport protocol messages and location interaction.
  • 2, REST-based Web Service: REST (Representational State Transfer) is a software architecture that uses JSON data format to describe the most important thing is to REST HTTP transport protocol is non-essential.

3-4, REST and SOAP distinction and connection

Here, to compare the similarities and differences between REST and SOAP through a form:

to sum up

As mentioned above, we understand what is API, what is REST API, what is the relevant concept RESTful API and Web Service. Representative API Application Programming Interface, is a more general definition or a protocol as an interface between software programs communicate with each other exist. REST API is a subset of the API, all the REST API is API; RESTful API is a REST API architectural style of informal implementation. API and Web Service are the means of communication between service providers and service consumers. Finally, in order to quickly identify the differences between the API and Web Service, these two methods are different from organized into the following table:

Original: proper screening difference and the link between API & REST API & RESTful API & Web Service

Reproduced in: https: //juejin.im/post/5d07317e6fb9a07eac05d33c

Guess you like

Origin blog.csdn.net/weixin_33712987/article/details/93180644