Home > Article > Backend Development > How to write an interface to display background data on the mobile APP
I just arrived at a new company. The company’s projects are mainly about apps. The data on the app is mainly through calling the data interface of the web backend. However, I have never been exposed to the interface before. Everything I did before was done in the web backend. I write the program code and then display it on the page. Now suddenly I come into contact with the interface and I really don’t know how to do it.
What I want to ask is, when writing an interface, do you need to implement the corresponding module function in the web background first? After writing an interface for it, the person responsible for APP development can directly call this interface to get data from the database? [Is this the principle?]
For example, as shown in the picture: I want to write an update announcement and security dynamic interface. Do I need to first implement the functions of these two modules in the web background, and then write an interface for each of them? If this is the case, what should be the basis for writing this interface, and what data or parameters should be used. What is the format
I just arrived at a new company. The company’s projects are mainly about apps. The data on the app is mainly through calling the data interface of the web backend. However, I have never been exposed to the interface before. Everything I did before was done in the web backend. I write the program code and then display it on the page. Now suddenly I come into contact with the interface and I really don’t know how to do it.
What I want to ask is, when writing an interface, do you need to implement the corresponding module function in the web background first? After writing an interface for it, the person responsible for APP development can directly call this interface to get data from the database? [Is this the principle?]
For example, as shown in the picture: I want to write an update announcement and security dynamic interface. Do I need to first implement the functions of these two modules in the web background, and then write an interface for each of them? If this is the case, what should be the basis for writing this interface, and what data or parameters should be used. What is the format
Thank you for the invitation. It's very simple. You can treat the excuse as an ordinary web page request, or a form request on an ordinary web page. The difference is that the data on the ordinary web page needs to be queried and then rendered into a view file and displayed to the user through the browser. The interface is to query, insert, update, and delete based on different conditions. Then just return the final result to the client in Json
or xml
format.
The calling interface should have an interface document, which generally has the following points:
Explain the address of the interface
Parameters of the interface
Status code and data format returned by the interface
Let’s go straight to the code!
First call the interface:
Then the code of the interface:
This is how one project in our project calls data from another project. This is what I originally wrote (there may be some unreasonable things, such as verifying the requested IP, etc.) It should probably be like this. Whether the interface data is retrieved successfully or unsuccessfully, an identified status code will be returned. For example, I use status
here. What I return is generally in json format, which can be easily parsed by front-end and back-end calls.
(As for why you need to pass the name instead of the ID, because the user names in the two project data tables are the same but the IDs are different! ~ Don’t pay too much attention to the details)