As a cainiao programmer, the Code previously written is a type of mixed code and spam code. The method of completely separating the front and back ends is just introduced, mainly through API interfaces. So I would like to ask you, Daniel, how did you separate the frontend and backend development during project development? How to Use restfulAPI in a project? PH... as a cainiao programmer, the Code previously written is mixed code, a type of spam code. It was just exposed to completely separate the front and back ends, mainly the API interface. So I would like to ask you, Daniel, how did you separate the frontend and backend development during project development? How to Use restfulAPI in a project? What are the differences between the interfaces of PHP for front-end, IOS, and Android? I hope you can give me a systematic lecture. Thank you!
Reply content:
As a cainiao programmer, the Code previously written is a type of mixed code and spam code. The method of completely separating the front and back ends is just introduced, mainly through API interfaces. So I would like to ask you, Daniel, how did you separate the frontend and backend development during project development? How to Use restfulAPI in a project? What are the differences between the interfaces of PHP for front-end, IOS, and Android? I hope you can give me a systematic lecture. Thank you!
The first question you asked is the api design. The module is clear and can be used quickly.
The second question is the difference between browser frontend and mobile app. There are three points:
Generally, browsers do not have version compatibility issues. For apps, you need to consider how to route the api version. (At least the app needs to give you a version number)
You need to define a unified data format with the app, such as the classic
{"Code": "status code", "msg": "information", "data ":{}}
The permission verification for app interfaces is different. I suggest using https requests, and then implement a session mechanism similar to the browser.
For example, my recently written authentication is based on user-authorized app interface authentication.
If it is a pure interface, I used to provide the same content for web and APP interfaces, and I use json. Both the APP and web can parse json by myself.
If security is not considered, json is enough.
Frontend and backend separation is nothing more than the absence of dependencies between frontend and backend writing. The only connection is the API interface pre-defined based on the function.
Since there is no dependency before and after, the web and mobile interfaces can be unified.
Output json to check whether the interface needs to be encrypted
Http://doc.thinkphp1.cn/manual/rest_intro.html
The above is the declaration and Writing Method of thinkphp rest api. This is a basic solution and is sufficient for general projects.
In addition to providing data, the complete WEBAPI also plays an important role in authentication and permission resource management. Currently, systems with strong data center capabilities (such as drupal8 and magento2) have improved WEBAPI functions and data backend. Therefore, you can consider using these open-source systems as backend data centers, it saves a lot of time for development.
Smarty template engine