As a rookie program ape, previously written code are mixed code, a class of garbage code, just touch to the front and back of the complete separation of the wording, mainly API interface. So I want to ask you, Daniel, how do you do the project when the back-end separation development? How do I use RESTFULAPI in a project? PHP to the front desk, IOS, Android interface what is different? I hope to have a system to tell me, thank you
Reply content:
As a rookie program ape, previously written code are mixed code, a class of garbage code, just touch to the front and back of the complete separation of the wording, mainly API interface. So I want to ask you, Daniel, how do you do the project when the back-end separation development? How do I use RESTFULAPI in a project? PHP to the front desk, IOS, Android interface what is different? I hope to have a system to tell me, thank you
The first one you ask is the design of the API, look at the team, the module is clear, can be used quickly.
The second you ask is the difference between the browser front end and the mobile app. The following 3 points are available:
browsers, in general, do not have version compatibility issues. And to the app you need to consider, API version processing, how to route. (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" : "状态码", "msg" : "信息", "data" : { }}
The app interface does not have the same permissions validation, my suggestion is to take the HTTPS request and then implement a browser-like session mechanism
For example, the authentication I wrote recently was based on user-authorized app interface authentication
If it is a pure interface, I used to give Web,app interface content is the same, all with JSON, regardless of the app and the Web, can parse their own JSON
If you don't consider security, it's enough to use JSON directly.
Front-end separation is nothing more than the frontend and the back end of each write The independent, the only link is pre-determined by the function API interface
Since there is no dependency, the interface between the web and mobile calls can naturally be unified
Output JSON to see if the interface needs to be encrypted
Http://doc.thinkphp.cn/manual/rest_intro.html
The above is the Thinkphp REST API declaration and writing method, this is a very basic scenario, for the general project is sufficient.
In addition to the complete WEBAPI can provide data, authentication and authority resource management are very important. At present, the data center ability of the system (such as Drupal8, MAGENTO2, etc.) has been improved WEBAPI function and data backstage, so it is also possible to consider using these open source systems as a back-end data center, will save a lot of development time.
Smarty Template engine