nginx+php+flight 构建RESTFul API
配置:
Nginx:
conf目录下nginx.conf配置文件。
第44行改为:root D:/wwwroot/www;
第45行改为:index index.html index.htm index.php; 加了PHP文件支持。
第65至71行改为:
(改为)location ~ \.php$ {
root D:/wwwroot/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME D:/wwwroot/www$fastcgi_script_name;
include fastcgi_params;
}
(原来)location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
}
d:/wwwroot为网站的根目录。此目录也可以重新配置。找到代码:
location / {
root html;
index index.html index.htm index.php;
}
PHP:
查找定位至:;extension=php_gd2.dll,将前面的分号去掉为:extension=php_gd2.dll
查找定位至:;extension=php_mbstring.dll,将前面的分号去掉为:extension=php_mbstring.dll
查找定位至:;extension=php_mysql.dll,将前面的分号去掉为:extension=php_mysql.dll
查找定位至:;extension=php_mysqli.dll,将前面的分号去掉为:extension=php_mysqli.dll
查找定位至:;extension=php_pdo_mysql.dll,将前面的分号去掉为:extension=php_pdo_mysql.dll
查找定位至:;cgi.force_redirect = 1,将前面的分号去掉为:cgi.force_redirect = 1
查找定位至:;cgi.fix_pathinfo=1,将前面的分号去掉为:cgi.fix_pathinfo=1
查找定位至:;cgi.rfc2616_headers = 0,将前面的分号去掉并改为:cgi.rfc2616_headers = 1
flight源码包:https://github.com/mikecao/flight
Demo:index.php
<?php
require_once('flight/Flight.php');
require_once('response.php'); header("Content-Type:application/json"); function db()
{
$conn = mysql_connect("127.0.0.1","root","");
mysql_query("SET NAMES UTF8");
return $conn;
} function get_user_list()
{
$users =array();
$sql = "select * from wordpress.wp_users";
$result = mysql_query($sql,db());
while ($row = mysql_fetch_array($result)) {
$users[] = array('user_id'=>$row['ID'],
'user_login'=>$row['user_login'],
'user_nicename'=>$row['user_nicename'],
'user_email'=>$row['user_email'],
'user_registered'=>$row['user_registered'],
'user_name'=>$row['display_name']);
} return $users;
} function get_user_derail($id)
{
$user =array();
$sql = "select * from wordpress.wp_users where id=".$id;
$result = mysql_query($sql,db());
while ($row = mysql_fetch_array($result)) {
$user = array('user_id'=>$row['ID'],
'user_login'=>$row['user_login'],
'user_nicename'=>$row['user_nicename'],
'user_email'=>$row['user_email'],
'user_registered'=>$row['user_registered'],
'user_name'=>$row['display_name']);
} return $user;
} Flight::route('/users', function(){
$users = get_user_list();
Response::show('200','返回成功',$users);
}); Flight::route('/users/@id', function($id){ $user = get_user_derail($id); if(!empty($user))
{
//Flight::json($user);
Response::show('200','返回成功',$user);
}
else
{
Response::show('404','资源不存在',$user);
}
}); Flight::start();
?>
GET: http://localhost:8090/users
{
code: "200",
message: "返回成功",
data: [
{
user_id: "1",
user_login: "11",
user_nicename: "11",
user_email: "11.cd@11.corp",
user_registered: "2014-05-07 02:33:19",
user_name: "111"
},
{
user_id: "2",
user_login: "leoliu",
user_nicename: "leoliu",
user_email: "leo.j.liu@11.com",
user_registered: "2014-05-07 02:54:07",
user_name: "刘, 建波"
},
{
user_id: "3",
user_login: "1",
user_nicename: "1",
user_email: "11.j.11@11.com",
user_registered: "2014-05-07 02:59:24",
user_name: "吴, 11"
}
]
}
GET:http://localhost:8090/users/{userId}
{
code: "200",
message: "返回成功",
data: [
{
user_id: "3",
user_login: "1",
user_nicename: "1",
user_email: "11.j.11@11.com",
user_registered: "2014-05-07 02:59:24",
user_name: "吴, 11"
}
]
}
nginx+php+flight 构建RESTFul API的更多相关文章
- Spring MVC中使用 Swagger2 构建Restful API
1.Spring MVC配置文件中的配置 [java] view plain copy <!-- 设置使用注解的类所在的jar包,只加载controller类 --> <contex ...
- 使用Express构建RESTful API
RESTful服务 REST(Representational State Transfer)的意思是表征状态转移,它是一种基于HTTP协议的网络应用接口风格,充分利用HTTP的方法实现统一风格接口的 ...
- SpringBoot 构建RestFul API 含单元测试
相关博文: 从消费者角度评估RestFul的意义 SpringBoot 构建RestFul API 含单元测试 首先,回顾并详细说明一下在快速入门中使用的 @Controller . @RestC ...
- Springboot 如何加密,以及利用Swagger2构建Restful API
先看一下使用Swagger2构建Restful API效果图 超级简单的,只需要在pom 中引用如下jar包 <dependency> <groupId>io.springfo ...
- springboot集成swagger2构建RESTful API文档
在开发过程中,有时候我们需要不停的测试接口,自测,或者交由测试测试接口,我们需要构建一个文档,都是单独写,太麻烦了,现在使用springboot集成swagger2来构建RESTful API文档,可 ...
- 集成swagger2构建Restful API
集成swagger2构建Restful API 在pom.xml中进行版本管理 <swagger.version>2.8.0</swagger.version> 给taosir ...
- 使用ASP.NET Core 3.x 构建 RESTful API - 1.准备工作
以前写过ASP.NET Core 2.x的REST API文章,今年再更新一下到3.0版本. 先决条件 我在B站有一个非常入门的ASP.NET Core 3.0的视频教程,如果您对ASP.NET Co ...
- 使用ASP.NET Core 3.x 构建 RESTful API - 2. 什么是RESTful API
1. 使用ASP.NET Core 3.x 构建 RESTful API - 1.准备工作 什么是REST REST一词最早是在2000年,由Roy Fielding在他的博士论文<Archit ...
- 使用 Spring Boot 构建 RESTful API
1. 使用 Idea 创建 Spring Initializer 项目 在创建项目的对话框中添加 Web 和 Lombok,或者建立项目后在 pom.xml 中添加依赖: <dependency ...
随机推荐
- ThinkPHP之中getlist方法实现数据搜索功能
自己在ThinkPHP之中的model之中书写getlist方法,其实所谓的搜索功能无非就是数据库查询之中用到的like %string%,或者其他的 字段名=特定值,这些sql语句拼接在and语句 ...
- php对数组排序的例子
分享一个php数组排序的例子,介绍了和php,有关的知识.技巧.经验,和一些php源码等. <?php class='pingjiaF' frameborder='0' src='http:// ...
- apache2反向代理node.js应用
在之前记录的随笔中,只是介绍了怎么在apache2中使用proxy模块,后来查到了一些资料,可以通过下面网址查看配置块的详细参数信息 http://man.ddvip.com/soft/apache2 ...
- 【Delphi】注册快捷键
ShortCutToText , TextToShortCut 需 uses Menus; type TForm1 = class(TForm) HotKey1: THotKey; Button1: ...
- python Django 学习笔记(二)—— 一个简单的网页
1,创建一个django项目 使用django-admin.py startproject MyDjangoSite 参考这里 2,建立视图 from django.http import HttpR ...
- DB2查看用户表与指定用户表表结构
1.在dos中查看用户表 1.1查看表 DB2 LIST TABLES FOR USER 1.2 查看表结构 DB2 describe table A 2.在DB2连接工具中(这里以SQLdbx为例子 ...
- hdu 1042 N!
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1042 N! Description Given an integer N(0 ≤ N ≤ 10000) ...
- Oracle 11gR2 Database和Active Data Guard迁移案例
客户一套核心系统由一台Oracle Database 11.2.0.3.4单机和一台Active Data Guard组成,分别运行在两台PC服务器上,Oracle Linux 5.8 x86_64b ...
- SQL-Server数据库学习笔记-表
1. 表及其属性 表(Table):也称实体,是存储同类型数据的集合. 列(Field):也称字段.域或属性,它构成表的架构,具体表示为一条信息中的一个属性. 行(Row):也称元组(Tuple),存 ...
- inout用法浅析
inout io_data; reg out_data; reg io_link; assign io_data=io_link? out_data:'bz; //当IO_data作为输入口使用时,一 ...