当前位置:网站首页>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=femaleCopy
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 :

边栏推荐
- 【C语言】分支和循环语句(上)
- Leetcode-934: the shortest Bridge
- Leetcode-849: maximum distance to the nearest person
- Test shift right: Elk practice of online quality monitoring
- [love crash] neglected details of gibaro
- 数据分析思维分析犯法和业务知识——分析方法(一)
- 瑞萨电子RZ/G2L开发板上手评测
- Foundations of data science is free to download
- 鏈錶內指定區間反轉
- 瑞萨RZ/G2L ARM开发板存储读写速度与网络实测
猜你喜欢

飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022

Web2.0 giants have deployed VC, and tiger Dao VC may become a shortcut to Web3

Illustrated network: what is virtual router redundancy protocol VRRP?
![[case sharing] let the development of education in the new era advance with](/img/11/af88d16dc66f00840cbfc5ba5d68bd.jpg)
[case sharing] let the development of education in the new era advance with "number"
![[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)](/img/f5/3ec22f1480227f33a1c8ac457155ed.jpg)
[flutter] icons component (load the built-in icon of flutter | display the material design icon completely)

基于ARM RK3568的红外热成像体温检测系统

excel去除小数点后面的数据,将数字取整

【AutoSAR 十一 通信相关机制】

【AutoSAR 三 RTE概述】

Basic use of sringcloud & use of component Nacos
随机推荐
【C语言】分支和循环语句(上)
[shutter] image component (configure local GIF image resources | load placeholder with local resources)
What is needed to develop a domestic arm intelligent edge computing gateway
FPGA - 7 Series FPGA internal structure clocking -04- multi area clock
[AUTOSAR VI description document]
深度剖析数据在内存中的存储
Cordova plugin device obtains the device information plug-in, which causes Huawei to fail the audit
测试右移:线上质量监控 ELK 实战
Linear programming of mathematical modeling (including Matlab code)
飞凌搭载TI AM62x的ARM核心板/开发板首发上市,亮相Embedded World 2022
18_微信小程序之微信视频号滚动自动播放视频效果实现2.0
【小程序项目开发-- 京东商城】uni-app之自定义搜索组件(中)-- 搜索建议
详解RDD基本概念、RDD五大属性
465. 最优账单平衡 DFS 回溯
Leetcode-849: maximum distance to the nearest person
How to systematically learn machine learning
Unity learns from spaceshooter to record the difference between fixedupdate and update in unity for the second time
Web2.0的巨头纷纷布局VC,Tiger DAO VC或成抵达Web3捷径
电话网络问题
KingbaseES ALTER TABLE 中 USING 子句的用法