RESTful-API questions about PHP

Source: Internet
Author: User
Keywords Php restful
Tags smarty template
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:

    1. 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)

    2. You need to define a unified data format with the app, such as the classic

{    "code" : "状态码",    "msg" : "信息",    "data" : {    }}
    1. 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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.