大佬教程收集整理的这篇文章主要介绍了php基于curl扩展制作跨平台的restfule 接口,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
restfule 接口 适用的平台:跨平台 所依赖:curl扩展 git:
PHP;">class apiServer
{
/**
/**
/**
/**
/**
$this->method = strtolower($_SERVER['REQUEST_METHOD']);
//所有的请求都是pathinfo模式
$pathinfo = $_SERVER['PATH_INFO'];
//将pathinfo数据信息映射为实际请求<a href="http://code.js-code.com/tag/fangfa/" target="_blank" class="keywords">方法</a>
$this->getResourse($pathinfo);
//<a href="http://code.js-code.com/tag/huoqu/" target="_blank" class="keywords">获取</a>传输的具体参数
$this->getData();
//执行响应
$this->doResponse();
}
/**
// 将pathinfo数据信息映射为实际请求方法
private function getResourse($pathinfo){
/**
* 将pathinfo数据信息映射为实际请求<a href="http://code.js-code.com/tag/fangfa/" target="_blank" class="keywords">方法</a>
* GET /users: 逐页列出所有<a href="http://code.js-code.com/tag/yonghu/" target="_blank" class="keywords">用户</a>;
* POST /users: 创建<a href="http://code.js-code.com/tag/yige/" target="_blank" class="keywords">一个</a><a href="http://code.js-code.com/tag/xinyonghu/" target="_blank" class="keywords">新用户</a>;
* GET /users/123: 返回<a href="http://code.js-code.com/tag/yonghu/" target="_blank" class="keywords">用户</a>为123的详细信息;
* PUT /users/123: 更<a href="http://code.js-code.com/tag/xinyonghu/" target="_blank" class="keywords">新用户</a>123;
* deletE /users/123: <a href="http://code.js-code.com/tag/shanchu/" target="_blank" class="keywords">删除</a><a href="http://code.js-code.com/tag/yonghu/" target="_blank" class="keywords">用户</a>123;
*
* 根据以上规则,将pathinfo第<a href="http://code.js-code.com/tag/yige/" target="_blank" class="keywords">一个</a>参数映射为需要操作的数据表,
* 第二个参数映射为操作的id
*/
$info = explode('/',ltrim($pathinfo,'/'));
list($this->resourse,$this->resoursEID) = $info;
}
/**
/**
/**
/**
/**
/**
/**
try{
if(!in_array($stat,array_keys($status))){
throw new Exception('输入的状态码不合法');
}else{
echo json_encode($status[$stat]);
}
}catch (Exception $E){
die($e->getmessage());
}
}
}
以上是大佬教程为你收集整理的php基于curl扩展制作跨平台的restfule 接口全部内容,希望文章能够帮你解决php基于curl扩展制作跨平台的restfule 接口所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。