当前位置:网站首页>Correctly distinguish the similarities and differences among API, rest API, restful API and web service
Correctly distinguish the similarities and differences among API, rest API, restful API and web service
2022-07-03 01:02:00 【Dusk on the cloud】
notice API What do you think of ? It's the interface 、 Third party call 、 still API file ? At first glance, you may think this is too familiar , Isn't this a daily series of system development ? But think about it , You'll find that API The concept of is so vague in your mind . How do you search through search engines API, You will see information like this :API——Application Programming Interface( Application programming interface ), This is too abstract . Next , I will combine some experience I have summarized in the development , Talk in a popular way API、REST API、RESTful API as well as Web Service The connection and difference between these four .
1、API And REST API
What is? API? Here is the definition given by Wikipedia : Application program interface ( English :Application Programming Interface, abbreviation :API; Also known as application programming interface ) It is an agreement on the connection of different components of the software system . This pair API The definition of is too broad and abstract , And in general ,API It is the interaction between one application and another application “ communication ” The way ( agreement ). stay Web Application development ,API It is a main way of data retrieval through the network ,API The document will inform you of the URL list 、 Query parameters 、 Request mode and response status , Its purpose is to reduce Web Difficulty of application development , Share data between two applications ( Text 、 Audio 、 video 、 Pictures, etc ), And shield its internal complex implementation details .
REST yes Representational State Transfer Abbreviation , The literal translation is : State the transition .REST API It's a group about how to build Web Applications API Architecture rules for 、 Standards or guidelines , Or say REST API It's following API An architectural style of principles .REST It's specifically for Web Designed for application , The goal is to reduce the complexity of development , Improve the scalability of the system . Here is the design REST Some basic conditions and principles that need to be met or followed when designing a style system architecture :
- 1、 stay REST Architecture ,Web Everything in ( Text 、 Audio 、 video 、 picture 、 link ) Can be uniformly abstracted as resources (resource)
- 2、 stay REST Architecture , Each resource has its corresponding unique resource identifier (resource identifier), When the state of a resource changes , The resource identifier will not change
- 3、 stay REST Architecture , All operations are stateless .REST Architecture follows CRUD principle , All resources are available through GET、POST、PUT and DELETE These four behaviors complete the corresponding operations .
- 4、 Caching ( optional ), stay REST Caching is needed in the architecture to effectively handle large numbers of requests
- 5、 Interface consistency
Now? , I understand API and REST API Basic concepts of , What are the similarities and differences between the two ? If we explain it according to the concept of set in Mathematics API And REST API The connection and difference between ,API yes REST API Superset ,REST API yes API Subset ; be-all REST API All are API, But not all API All are REST API. A more popular explanation is : All men are human , But not everyone is a man .
2、REST API And RESTful API
In the first section , I learned what is REST API, Let's talk about REST API And RESTful API The similarities and differences between . Many beginners can easily equate the two , Think RESTful API Namely REST API, This may be simply understood literally , When you deeply understand the essence of both , You will find that it is not .REST API yes Web API A specification or guiding principle of design , and RESTful API It is a specific implementation of the architecture design principles or specifications . in other words ,RESTful API yes REST API Informal implementation of , Because of the realization of REST API There are many ways ,RESTful API It's just one of them , And not completely satisfied REST API All design principles of , Every developer is implementing REST The emphasis of architecture will be different .
Many beginners are easy to learn REST API And RESTful API The two concepts are confused , I think it's just literally , Without paying attention to their own meaning ( Just like knowing Chinese characters , Read while , Boundless reading in the middle , Taken out of context ). This is like many people will equate transgender people with women , Transgender people may have facial features that look like women , But transgender people are infertile , It just meets most of the conditions that define a woman ( Realization ), But not women in essence .
Next , Through a simple example to deepen the understanding of REST API and RESTful API The understanding of the . An implementation is given below CURD Operation of the RESTful API Design case :
explain :resource Refers to the name of a resource , When you can student( Student )、teacher( teacher )、book( Books ) wait , Nouns are usually used to express ;{id} It refers to the unique identifier of a resource (resource identifier)
Here is a specific example , Take student management as an example , Design student management API. Student resources include ID, Name and course information , Student resource information is as follows :
Now? , We need to save student data to database , Then execute the query 、 Operation of modifying and deleting student data . Student management API Called by the user of API as follows :
- 1、 Create student resources :[POST] http://www.example.com/student
- 2、 Get all student resources :[GET] http://www.example.com/students
- 3、 obtain ID=1001 Student resources :[GET] http://www.example.com/student/1001
- 4、 modify ID=1001 Student resources :[PUT] http://www.example.com/student/1001
- 5、 Delete ID=1001 Student resources :[DELETE] http://www.example.com/student/1001
The previous content says ,API Sharing data resources , And shielding the internal implementation ,API Users of ( client ) Focus on resources ( Read the data ), You don't need to know API Internal construction ;API The provider of ( Server side ) Only focus on your own internal implementation , It doesn't matter API Users ( client ) The state of . In order to deepen the understanding of this concept , Student management is given below API Internal implementation example of :
explain : The sample code is based on Spring MVC Implemented .
In addition to the above , You can also filter the query data by providing key value pairs , For example, when obtaining all student data , Just want to get the data of female students , It can be done in this way :
[GET] http://www.example.com/students?gender=female
Copy
Tip: If API It has the function of data filtering , Corresponding to the server API The implementation code also needs to be adjusted .
In the previous content , We mentioned RESTful API yes REST API Informal implementation or specification of . Why do you say that ? Because in RESTful API In the design of , We can go through GET By CURD operation , It can also be done through DELETE Behavior to create resources , adopt POST Behavior to modify resources , Its implementation method is not rigorous or not strictly in accordance with REST API Proposed constraints . So RESTful API yes REST API Informal implementation of .
3、REST And Web Service
3-1、 What is? Web Service?
Such as the World Wide Web Consortium (W3C) Described ,Web Service It is available on various platforms and / Or the standard method of interoperability between different software applications running on the framework .Web Service Is characterized by good interoperability and scalability , And due to the use XML It can describe the process of program processing . They can combine different services in a loosely coupled manner to achieve complex operations . Programs that provide simple services can interact with each other , To provide complex value-added services .
Two Web Service It's mainly through HTTP Network protocol for communication , As we know SOA( Service oriented architecture ), Mainly depends on XML-RPC and SOAP(Simple Object Access Protocol, Simple object access protocol ).
Tip: Never put SOA( Service Oriented Architecture ) and SOAP( Simple object access protocol ) Mix up , The former is a form of architecture design , The latter is a data exchange protocol .
A simple example : Suppose a Web Service A Provide to allow other applications to pass URL Access to user information :[GET] http://www.abc.com/{id}.id Is the unique identifier of the user , Request this URL User information will be obtained . Now suppose the browser 、 mobile phone 、 Users of desktop applications need access to services A User information provided , These three only need to request services A Provided URL Address , And enter the user id Information is enough . As for the implementation of the three different clients ( programing language ) What and service A It doesn't matter , As long as the service can be parsed A Back to XML Just documents . such , The exchange of data between applications can be independent of the specific language and environment . This is like people in different countries and languages , As long as you can know the grammatical structure of the other language , Two people can communicate .
3-2、Web Service The advantages of
Use Web Service It has the following advantages :
- 1、 Interoperability :Web Service Allow communication between applications , Exchange data and share services .
- 2、 Usability :Web Service The function of can be found from simple information to complex algorithm calculation .
- 3、 Reusability :Web Service They can be combined with each other , To provide more complex services , Because of its interoperability , It can be easily reused in other services Web Service Components , Improve the reuse rate of services .
- 4、 Easy to deploy :Web Service Can be deployed based on Internet The standard Containers in , Such as Apache、Axis2 etc. , In order to provide HTTP perhaps WSDL( Web service definition language ) Driven services .
- 5、 The cost is low :Web Service It is packaged into Web Deploy service components , Thus reducing the cost of use .
3-3、Web Service The type of
at present ,Web Service There are two main schools :
- 1、 be based on SOAP Of Web Service : SOAP( Simple object access protocol ) It's based on XML The agreement , To visit Web Service. Its interface is described in a machine processable format , be called WSDL(Web Service definition language ) file . By using standard XML Document to describe Web Service, stay XML In file , The interface information will be recorded in detail , Such as message format 、 Transmission protocol, location of interaction and other information .
- 2、 be based on REST Of Web Service :REST(Representational State Transfer) It's a software architecture , It USES JSON To describe the data format , most important of all HTTP Transmission protocol pair REST It is not necessary .
3-4、REST And SOAP The difference and connection
below , Use a table to compare REST And SOAP The similarities and differences between :
summary
As mentioned above , We know what is API, What is? REST API, What is? RESTful API as well as Web Service Related concepts of .API Represents the application programming interface , It is a relatively broad definition or an agreement , It exists as an interface for software programs to communicate with each other .REST API yes API A subset of , be-all REST API All are API;RESTful API It's right REST API An informal implementation of architectural style .API And Web Service Both are means of communication between service providers and service consumers . Last , In order to quickly identify API And Web Service Differences between , The differences between these two methods are sorted into a comparison table as follows :
边栏推荐
- 【AutoSAR 一 概述】
- Liad: the consumer end of micro LED products is first targeted at TVs above 100 inches. At this stage, it is still difficult to enter a smaller size
- 18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
- cordova-plugin-device获取设备信息插件导致华为审核不通过
- 瑞萨电子RZ/G2L开发板上手评测
- Understanding and distinguishing of some noun concepts in adjustment / filtering
- 全志A40i/T3如何通过SPI转CAN
- leetcode-2115:从给定原材料中找到所有可以做出的菜
- 解决ReactNative使用webView存在缓存问题
- Arduino开发之按键检测与正弦信号输出
猜你喜欢
【AutoSAR 五 方法论】
Vulkan practice first bullet
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)
[overview of AUTOSAR three RTE]
Matlab saves the digital matrix as geospatial data, and the display subscript index must be of positive integer type or logical type. Solve the problem
[AUTOSAR VI description document]
指针进阶(一)
Rust ownership (very important)
[introduction to AUTOSAR seven tool chain]
Test shift right: Elk practice of online quality monitoring
随机推荐
How to find out the currently running version of Solr- How do I find out version of currently running Solr?
文件操作IO-Part2
【AutoSAR 十 IO架构】
[AUTOSAR twelve mode management]
百度智能云牵头打造智能云综合标准化平台
链表内指定区间反转
AEM: Nanlin fan Ben et al. - plant rhizosphere growth promoting bacteria control soybean blight
Win10 多种方式解决无法安装.Net3.5的问题
18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
Leetcode-241: designing priorities for operational expressions
【AutoSAR 十一 通信相关机制】
Vulkan-性能及精细化
RK3568开发板评测篇(二):开发环境搭建
Leetcode-871: minimum refueling times
用Go+绘制爱心给心爱的她表白
鏈錶內指定區間反轉
leetcode-1964:找出到每个位置为止最长的有效障碍赛跑路线
excel表格计算时间日期的差值,并转化为分钟数
Advanced pointer (I)
[overview of AUTOSAR three RTE]