One check interface
Recently, I need to connect to an external interface. The basic function is to verify whether the specified store has complete shipping information. The interface looks something like this:
POST https://******/Dealer/CheckCarrier Heads:Authorization=****,Content-Type=application/x-www-form-urlencoded Request Body:DealerCode=**,StoreCode=**,BrandCode=**,BuCode=** Response Body: {"success":true,"message":" operation succeeded ","data":"OK"}Copy the code
The structure of this Response is not unfamiliar to you.
First question
When I got this socket, I felt a little strange. ** if it is a check interface, the result should be true or false. ** So, with doubt, I went to peer A who provided the interface.
Peer A replied that ** does not care about data, and the verification result is put in success? ** At this time, there were more question marks on my head. I felt strange and couldn’t tell why.
Second question
After A moment’s reflection, I realized the root of my confusion — colleague A’s understanding of Response was different from mine. In my opinion, regardless of the interface, data puts the final result, while SUCCESS puts whether the call completed properly.
For this interface, success should be true as long as the validation is complete, regardless of whether the specified store has complete shipping information.
So when is it false? Return false if the validation fails for some reason, for example, the entry is illegal or the store is not maintained, and these reasons will be put into message. If the caller wants to know what type of exception it is, it can do so by adding a code field (I don’t think the caller needs to know).
Have I been wrong this whole time?
I tried to communicate with colleague A about this problem, but after A lot of nonsense, colleague A didn’t seem to understand my doubts.
Maybe I’m not being clear, but I’m trying to say it figuratively: I’d like to see if there’s any meat upstairs. “Data” is the final result, that is, whether there is meat. When “success” is true, it means THAT I successfully climbed the leak and confirmed whether there is meat. When “success” is false, it may be because I fell on the stairs and could not confirm whether there is meat.
Finally, peer A seemed to recognize my logic, of course, the people may be that I am too tired, do not want to spend more time with me.
conclusion
So, I want to know how you understand Response.
Finally, thank you for reading, welcome private communication.
The 2021-11-16 supplement
After 2021-11-14 posted the article, it received a lot of feedback.
First of all, thank you: for my doubts, many enthusiastic garden friends gave their own views, let me harvest a lot.
Secondly, I am also very sorry: due to my improper expression, many people confuse the Response in the article with the Response in HTTP. I’ll fill in the instructions here.
This article original articles, reproduced please attach the original source link: www.cnblogs.com/ZhangZiShen…