定制 palanik/restslim 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

palanik/restslim

Composer 安装命令:

composer require palanik/restslim

包简介

Minimalist REST framework for PHP Slim.

README 文档

README

Latest Stable Version License

Minimalist REST framework for Slim.

Slim is a PHP micro framework that helps you quickly write simple, yet powerful web applications and APIs.

Shift your focus from Routes to Resources, while building RESTful API with PHP Slim.

##Installation You can install via composer. Add this to your composer.json

{
  "require": {
    "slim/slim": "2.4.*",
    "palanik/restslim": "0.1.*"
  }
}

Greetings Tutorial

$app = new \Slim\Slim();

// This should obviously go in a datastore
$data = array();
$data["1"] = array("id" => 1,
                "message" => "Hello, World!");
$data["2"] = array("id" => 2,
                "message" => "Good Bye!");


$greetings = new \RestSlim\RestSlim("greetings");

// List
$greetings->list(function() use ($app, $data) {
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->write(json_encode($data, JSON_NUMERIC_CHECK));
});

// Read
$greetings->get(function($id) use ($app, $data) {
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->write(json_encode($data[$id], JSON_NUMERIC_CHECK));
});

// Create
$greetings->create(function() use ($app, $data) {
	$request = $app->request();
	$message = json_decode($request->getBody(), true);
	$id = count($data) + 1;
	$message["id"] = $id;
	$data[$id] = $message;
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->write(json_encode($data, JSON_NUMERIC_CHECK));
})
// Update
$greetings->update(function($id) use ($app, $data) {
	$request = $app->request();
	$message = json_decode($request->getBody(), true);
	$message["id"] = $id;
	$data[$id] = $message;
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->write(json_encode($data, JSON_NUMERIC_CHECK));
})
// Delete
->delete(function($id) use ($app, $data) {
    $app->response->headers->set('Content-Type', 'application/json');
    $app->response->write(json_encode($data[$id], JSON_NUMERIC_CHECK));
    unset($data[$id]);
});

// Inject into Slim
$greetings->app($app)
            ->run();

Slim applications are built by mapping routes to callback functions for specific HTTP request methods. But, RESTFul APIs are more about resources and actions on the resources, than about the routes. RestSlim brings the two together. It enhances Slim in creating RESTful applications with ease.

Create action oriented, restful resources independently and then inject them to your Slim application. Add multiple resources to the same Slim app.

Although, you create your resources independently, RestSlim integrates with a Slim application to serve the resources.

RestSlim adheres to Slim framework's guiding principle: Cleanliness over terseness and common cases over edge cases.

License

MIT

统计信息

  • 总下载量: 58
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-10-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固