当前位置:网站首页>Yyds dry inventory company stipulates that all interfaces use post requests. Why?
Yyds dry inventory company stipulates that all interfaces use post requests. Why?
2022-07-02 16:14:00 【Menong Xiaosong】
When I saw this question, I actually felt it very much , Because I once asked myself . When I was in the last company, I received a project to build a micro service from scratch , At that time, I knew some specifications of the interface , Like the familiar ones Restful standard , It is applied to this micro service project .
See this problem again today , I also have some new understanding and feelings , A temporary review get And post Some of the differences in your request :
- post More secure ( Not as url Part of , Will not be cached 、 Save in server log 、 And browser browsing records )
- post The data sent is bigger (get Yes url Length limit )
- post Can send more data types (get Can only send ASCII character )
- post Than get slow
- post Used to modify and write data ,get Generally used for search sorting and filtering operations
- get Static resources are requested , It will cache , If it's data , Will not cache
See the difference above , You will find post When sending requests with a large amount of data, the advantages are very obvious ,get It is more suitable to obtain static resources 、 Simple query and other interfaces .
I personally pay attention to when developing interfaces , Use... For simple query requests get Method , Other increases 、 Delete 、 Change 、 Complex query requests can use post, But it won't use it all like the company of the subject post.
Netizen Cheng mo Morgan Put forward that if you are yourself, you will follow 『 Industry best practices 』 Make rules :
published standard test papers Morgan
Another close friend suggested : To accommodate low-level architects and front-end and back-end programmers
.
The bosom friend replied
Wide and wide
Answer :
I'm going to jump out of the realm of Technology , from ROI Discuss the next architectural style from the perspective of ( such as Restful) Really so good , Why is it not so widely used ?
First of all, make it clear , No matter how much you like technology , Whether it's one here http Of method, Or some usage of programming language 、 Architecture design method 、 Even OKR Such a method of management and communication . All of this , All to meet the market demand of enterprises . Simply speaking , The company pays you , Not to make you abide by the rules , But to be able to... At an acceptable cost , Let the business land .
And one of , In general , The form of the interface is a trivial local problem . For enterprises , More important problems to be solved by the technical team , Is to understand the business model , Form a business architecture and a stable system ; It is the scalability guarantee that the system will not get stuck in the face of the requirements of a large number of users for system availability ; I don't go crazy , Stability requirements for lost data or data conflict , And various conveniences to the monitoring system in order to meet these requirements .
But be sure to tangle POST/GET, as well as Restful. ok ,Restful Can clearly list the benefits , Just a few points ( If there are omissions, please add in the comment area ):
- Express different business action semantics :GET/POST/PATCH/PUT/DELETE……,
- expression “ resources ” The concept of using
- url path,querystring,header,status code And so on to express many interface functions
- The above two can achieve one “ Unified ” Interface expression of , So that tools for interface maintenance can be implemented around this form , such as swagger.
- Get Resources can be cached
But at what cost ?
- Forced unification , The business concept that is not natural resources must also be enforced “ resources “ once , Caused more inconsistencies in understanding and communication difficulties . Of course , Things are always and can “ abstract ” once , The business concept is abstracted as “ resources ” Many times it is feasible . But the benefits of doing so apart from proving “ A man is clever , Good abstract ability “, as well as “ Easier to use swagger A kind of tool “ outside , I don't see any additional short-term or long-term benefits .
- maneuver path,querysting Things like that , Make it more difficult for cross-sectional governance to capture key information . For example, catch one during monitoring path With variables in it url It's a very disgusting thing . Or see a 404 The police , But I don't know what the problem is with service deployment ; The service is normal , But the user does not exist ; Or the user exists , But the user order does not exist . The problem is that it is difficult to write operation tools , Online problem response will be reduced .
- Even using swagger, You still need to write instructions and documents to explain its business semantics . Interface tools should provide “ A good understanding , After the interface is changed, the document is automatically generated ” Etc , Only the resources reflected in the interface just coincide with the background data table / The view is valid only when it can be mapped . In other words, it is only suitable for scenarios with low interface level , It has little significance for high-level interfaces . As a result, developers have to use swagger Such a tool , At the same time, it still depends on the general documents . The problems that can be solved by one mechanism should be changed into two .
- Cache Is good , But the most fear is that the control is not in place, so that users get expired data . about Cache, In business, dynamic interfaces and static interfaces are generally distinguished . The former should not have cache, So use the Get Then in order to prevent , You have to manually add... To most dynamic interfaces Cache-Control: no-cache, Or dynamically generate ETag( waste CPU). The latter will generally use CDN, This set is aimed at cache Made a very delicate design .
- Use different forms of method and url path,querystring Make all kinds of strange splices on , It will bring great trouble to the front end , Because originally a function call , I have to translate it again , Get an interface translation layer alive . Properly reduce human effect . If it is web,iOS,Android Three sets of front end , You have to do it 3 An interface translation layer .
- Not GET and POST In addition to the method It may be killed by inappropriate gateway forwarding rules . So Restful Still got method override Such a trick ……
So whether it's suitable or not , Just listen to the curse and quarrel when landing .
Someone raised Google S3 Application Restful Interface example to illustrate its correctness . but S3 Everyone knows what it is ,S3 Nature is used to access “ resources “ Of . A tool is used in the right scenario , Certainly ” correct “ Of .S3 Something good to use , It can only explain similar alicloud OSS, Tencent cloud COS You can do the same . But it can't prove that e-commerce business 、 Social business 、I Medical services 、 Government enterprise office coordination …… These businesses are also suitable for this .
As the technical director , If he comes up with an interface scheme ( Maybe one of them is all http All interfaces use post), Improved development efficiency , Reduce the cost of communication , Reduced O & M and error location costs , It has really achieved cost reduction and efficiency increase for the enterprise . The cost of fooling around , Invested in other, such as business architecture design , Test system , Online monitoring , Disaster recovery and degradation . Finally, let the enterprise ( User needs are met , Income increase ) And employees get benefits ( A rise in salary because of the increase in the company's income ). I will evaluate such people “ Really understand Architecture , Know technology , Be good at solving practical problems with technology . I don't know where the level is “
.
If a technical director only knows to abide by what is written in a Book , But I've never verified a solution that works in my own environment , So that the core goal of the enterprise can not be achieved . He is Zhao Kuo , It's time to pack up and go right away .
As for our company , The specification used is .
For dynamic business interfaces , There's only one interface POST /action, stay Header Li Gei X-Action Give the specific interface name to the gateway ,session Indicates the login identity of the user , And for recommending 、 Anti weight 、 dyeing 、 All kinds of... Used for safety token/ Signature . All business request parameters are expressed in PB After coding, put it in the request body , And with the backend gRPC System convergence . In addition to preventing retry, the interface , Do not provide... In the conventional sense Cache. For static interfaces , go CDN, Do multi-level Cache. This use Get use Get. If a dynamic interface also wants to take advantage of http layer Cache, You can request and configure from the gateway . Is there any Cache,cache How long is it implemented by the gateway and the end itself , Completely self-control .
边栏推荐
- Another graduation season
- Armv8-a programming guide MMU (4)
- OSPF - route aggregation [(summary) including configuration commands] | address summary calculation method - detailed explanation
- Practice of constructing ten billion relationship knowledge map based on Nebula graph
- PyC file decompile
- 触发器:Mysql实现一张表添加或删除一条数据,另一张表同时添加
- How to import a billion level offline CSV into Nepal graph
- Kubernetes family container housekeeper pod online Q & A?
- 可视化技术在 Nebula Graph 中的应用
- /Bin/ld: cannot find -lxml2
猜你喜欢
Boot transaction usage
2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
The light of ideal never dies
win10系统升级一段时间后,内存占用过高
mysql min() 求某条件下最小的值出现多个结果
处理gzip: stdin: not in gzip formattar: Child returned status 1tar: Error is not recoverable: exitin
JS learning notes - first acquaintance
图数据库|Nebula Graph v3.1.0 性能报告
智联招聘的基于 Nebula Graph 的推荐实践分享
Nebula Graph & 数仓血缘关系数据的存储与读写
随机推荐
关于mysql安装的一些问题
Practice of constructing ten billion relationship knowledge map based on Nebula graph
Comprehensively interpret the background and concept of service mesh
Data Lake (11): Iceberg table data organization and query
绝对真理和相对真理思考
Flink real-time data warehouse (7): Flink realizes the full pull module to extract data in MySQL
2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
mysql 计算经纬度范围内的数据
[solution] educational codeforces round 82
How to import a billion level offline CSV into Nepal graph
SQL modification statement
mysql min() 求某条件下最小的值出现多个结果
How to use percona tool to add fields to MySQL table after interruption
2022 the latest and most detailed will successfully set the background image in vscade and solve unsupported problems at the same time
Boot transaction usage
[idea] recommend an idea translation plug-in: translation "suggestions collection"
由ASP.NET Core根据路径下载文件异常引发的探究
Introduction to Dynamic Planning II (5.647.62)
JS learning notes - variables
Dimension table and fact table in data warehouse