Restful-php api Problems

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

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

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

{"Code": "status code", "msg": "information", "data ":{}}
  1. 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

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.