2 Star 0 Fork 0

tom / rester

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Rester

基于Slim + Laravel Eloquent的RESTful API框架。

由于Laravel的验证依赖了很多Symfony的组件,所以我简化了一个版本(validation),并引用到这个项目中。

#Usage

安装

请使用composer安装

git clone https://github.com/overtrue/rester
cd rester
composer install

虚拟机配置文件 vhost

路由:

app/routes.php

<?php

$app->get('/', function(){
    return json_encode(['hello' => 'world!']);
});

或者也可以使用控制器:

$app->get('/', 'HomeController:index'); //调用HomeController的index方法

更多路由的使用请阅读Slim官方文档:http://docs.slimframework.com/#Routing-Overview

控制器

<?php

/**
 * 演示控制器
 */
class HomeController extends Controller
{
    public function index() {
        return $this->json(['app' => 'Rester', 'message' => 'Hello world!']);
    }

    //...
}

控制器里有用的方法有:

  • $this->init()
    会在项目初始化完成后首先调用,可以用来做一些初始化或者每个方法都需要用到的动作,比如用户授权。

  • $this->json(mixed $data [, int $status = 200])
    输出json格式数据,第二个参数为状态码。

  • $this->jsonp(mixed $data [, string $callback = ''])
    输出jsonp数据,第二个参数为回调函数名,可选,为空默认从$_GET读取callback, 如果最终获取不到callback,输出等于$this->json

  • $this->validate(array $input, array $rules [, boolean $return = false])
    数据验证,默认验证失败主动返回错误json输出并停止往下运行,当$return = true时不停止运行,返回验证失败消息。

  • $this->error(string $message, int $status [, array $errors = []]) 输出错误json, $errors 为错误明细,通常为数组,可选。

更多数据验证规则请参阅:http://laravel.com/docs/4.2/validation

License

MIT

The MIT License (MIT) Copyright (c) 2014 Carlos - 安正超 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

基于Slim+Eloquent的RESTful API框架 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/fushanlang/rester.git
git@gitee.com:fushanlang/rester.git
fushanlang
rester
rester
master

搜索帮助