Newbie's first experience with php API php api documentation php api interface development php web ap

WBOY
Release: 2016-07-29 08:54:13
Original
1670 people have browsed it

Writing API in php here actually refers to providing a WebService

WebSite : 1.以html格式响应返回 2.由用户通过浏览器来接入 WebService : 1.以json/Xml格式返回 2.由程序接入 3.用来实现不同平台的交互
Copy after login

How to begin

To put it simply, it is to transmit data and encapsulate various methods for others to call

A simple example

How to Write an interface for student meal cards?

As an intermediate layer, we need to get the user's data (i.e. student's student ID number, student card password), and know where we should POST the data (such as www.123.com/Api/login), and understand Data format, we can start work.

The specific process is that after the user enters the username and password into the form, we receive the username and password, and then write them into the required data format, such as username="&password=", and then interact with the server through curl

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, count($fields)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_all); $data = curl_exec($ch); curl_close($ch);
Copy after login

This It is some key interaction code, among which$fields_all represents a part of a URL request written according to the data format and encoded by urlencode. And$fields represents the name of each data variable in$fields_all

The server will then have a returned json data, and it will be clear at a glance whether the data has been successfully interacted

Of course, this is just the simplest interaction, and there may be more When you encounter other confusing logic, you can only think about it slowly. In fact, those who are used to writing websites will still think that writing APIs is quite simple, but there is no sense of accomplishment...

Of course, this is not based on What is the restful style? The next article will briefly talk about the rest experience... Of course, it is also very exciting to use Yii and Laravel to develop with the framework. After all, others support rest..

Written by a pure novice, light spray.

 --by vampirebitter 
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces Xiaobai's first experience with PHP API, including api and PHP content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!