Home > Backend Development > PHP Tutorial > How to write an interface to display background data on the mobile APP

How to write an interface to display background data on the mobile APP

WBOY
Release: 2016-08-04 09:19:11
Original
1995 people have browsed it

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. How to write an interface to display background data on the mobile APP

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

Reply content:

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. How to write an interface to display background data on the mobile APP

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:

  1. Explain the address of the interface

  2. Parameters of the interface

  3. Status code and data format returned by the interface

Let’s go straight to the code!

First call the interface:

How to write an interface to display background data on the mobile APP

Then the code of the interface:

How to write an interface to display background data on the mobile APP

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.

How to write an interface to display background data on the mobile APP

(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)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template