2017 © Pedro Peláez
 

library restslim

Minimalist REST framework for PHP Slim.

image

palanik/restslim

Minimalist REST framework for PHP Slim.

  • Monday, May 4, 2015
  • by palanik
  • Repository
  • 1 Watchers
  • 0 Stars
  • 50 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

RestSlim

Latest Stable Version License, (*1)

Minimalist REST framework for Slim., (*2)

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

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

Installation

You can install via composer. Add this to your composer.json, (*5)

{
  "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., (*6)

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

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

RestSlim adheres to Slim framework's guiding principle: Cleanliness over terseness and common cases over edge cases., (*9)

License

MIT, (*10)

The Versions

04/05 2015

dev-master

9999999-dev https://github.com/palanik/RestSlim

Minimalist REST framework for PHP Slim.

  Sources   Download

MIT

The Requires

 

by Avatar palanik

api restful slim slimphp restslim

18/10 2014

v0.1.0

0.1.0.0 https://github.com/palanik/RestSlim

Minimalist REST framework for PHP Slim.

  Sources   Download

MIT

The Requires

 

by Avatar palanik

api restful slim slimphp restslim

13/10 2014

v0.0.1

0.0.1.0 https://github.com/palanik/RestSlim

Minimalist REST framework for PHP Slim.

  Sources   Download

MIT

The Requires

 

by Avatar palanik

api restful slim slimphp restslim