restfulapi 接⼝代码实例
class Request
{
//允许的请求⽅式
private static $method_type = array(‘get’, ‘post’, ‘put’, ‘patch’, ‘delete’);
//测试数据
private static $test_class = array(
1 => array(‘name’ => ‘托福班’, ‘count’ => 18),
2 => array(‘name’ => ‘雅思班’, ‘count’ => 20),
);
public static function getRequest()
{
//请求⽅式
_SERVER[‘REQUEST_METHOD’]);
if (in_array(method_type)) {
//调⽤请求⽅式对应的⽅法
$data_name = data_name($_REQUEST);
}
return false;
}
//GET 获取信息
private static function getData($request_data)
{
request_data[‘class’];
//GET /class/ID:获取某个指定班的信息
if (KaTeX parse error: Expected '}', got 'EOF' at end of input: …{ return self::test_class[KaTeX parse error: Expected 'EOF',got '}' at position 12: class_id]; } else {//GET /c…test_class;
}
}
//POST /class:新建⼀个班
private static function postData(KaTeX parse error: Expected '}', got 'EOF' at end of input: …) { if
(!empty(request_data[‘name’])) {
$data[‘name’] = $request_data[‘name’];
request_data[‘count’];
self::$test_class[] = test_class;//返回新⽣成的资源对象
} else {
百度api接口return false;
}
}
method =strtolower (method ,self ::method .‘Data ’;returnself ::class d =i (int )data [‘count ’]=(int )data ;returnself ::
//PUT /class/ID:更新某个指定班的信息(全部信息)
private static function putData($request_data)
{
request_data[‘class’];
if ($class_id == 0) {
return false;
}
request_data[‘name’]) && isset($request_data[‘count’])) {$data[‘name’] = $request_data[‘name’];
request_data[‘count’];
self::class_id] = test_class;} else {
return false;
}
}
//PATCH /class/ID:更新某个指定班的信息(部分信息)private static function patchData($request_data)
{
request_data[‘class’];
if (request_data[‘name’])) {self::class_id][‘name’] = KaTeX parse error: Expected 'EOF', got '}' at position 23: …_data[‘name’]; } if (isset(request_data[‘count’])) {
self::class_id][‘count’] = (int)KaTeX parse error: Expected 'EOF', got '}' at position 24: …data[‘count’]; } return self::test_class;
}class d =i (int )data =array ();if (!empty (data [‘count ’]=(int )test lass [c data ;returnself ::class d =i (int )class d =i =0)returnfalse ;if (!empty (test lass [c test lass [c
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论