In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is the API interface developed by PHP? in view of this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
PHP, the most popular server-side language, is very simple and advantageous in developing API. API architecture has become a common software architecture model in Internet product development, and many companies specializing in API services have been born.
Let's take a look at API:
1. API is more concise than developing WEB, but the logic may be more complex. API only returns the results, that is, it only outputs the data and does not render the page.
2. WEB development, more GET and POST requests, API and PUT, DELETE requests
3. Like WEB development, we first need some relevant parameters, which will be passed from the client, either GET or POST, which requires the development team to agree with each other or formulate a unified specification.
4. With the parameters, complete the data processing according to the application requirements, such as obtaining user information, sending moments, sending messages, submitting data at the end of a game, etc.
5. After the logical processing of the data, return the relevant data needed by the client, such as an array of user information, a list of moments, message status, game result data, and so on. How can the data be returned to the client? XML and JSON are common. Just set the corresponding header and print the data to be returned directly.
6. After the client gets the data you return, interact with the user locally on the client
So we probably know that there is no MVC architecture pattern in the Web domain in API. If you want to layer, there are only M and C layers in API. Of course, the back end may have a more complex architecture!
Understand how PHP develops API through the following API example of HTTP protocol:
Example of API output. A string of json is returned:
Json is cross-platform, and almost every language has a function to parse json. Here is an example of PHP as a client call:
Several points that we should pay attention to when developing API in the actual project
1. There are many ways to implement multiple interfaces in a single file, such as if..elseif... Or the unified entry used in switch or many frameworks is implemented by calling class functions.
2. Json,json is recommended for data output, which is highly cross-platform. Most programming languages support json parsing. Json is gradually replacing xml as the general format of network data.
3. In order to ensure the security of the interface, the authentication system must be added.
4. For online API, be sure to turn off all error display. You can write errors to the log, PHP, and block all errors through error_reporting (0).
On the one hand, the purpose of this is to protect the interface security and prevent the output of error messages that should not be printed.
On the other hand, it ensures that the output is in the correct data format, such as json. If it is not in the standard json format, the client will make errors in parsing, thus affecting the normal operation of the client.
PS: when we usually use the mobile phone APP, the phone will flicker, mostly because of this, that is, the API call is abnormal.
5, there is a certain difference between developing API and WEB. If it is WEB, if there is a problem with the writing of the program, such as a notice or warning-level error, there may not be any problem in WEB. It may just cause some part of WEB to misplace or garbled. However, if it is API, the client will be seriously called. If it is a mobile phone APP, it is inevitable to flash and push. If it is also a Web call, there may also be ServerError.
6. We must focus on stability and response speed, because when we use mobile phone APP, we do not want APP to flash frequently and want the application to be smooth.
This is the answer to the question about the development of API interface by PHP. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 242
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.