WellRESTed

WellRESTed is a library for creating RESTful APIs and websites in PHP that provides abstraction for HTTP messages, a powerful middleware system, and a flexible router.

<?php

use App\ServiceProvider;
use Pimple\Container;
use WellRESTed\Server;

require_once('vendor/autoload.php');

$c = (new Container())->register(new ServiceProvider())

$server = new Server();
$server
    ->add($c['errorHandler'])
    ->add($server->createRouter()
        ->register('GET', '/', $c['index'])
        ->register('GET', '/cats/', $c['getCatsList'])
        ->register('POST', '/cats/', [
            $c['auth'],
            $c['jsonParser']
            $c['postCat']
        ])
        ->register('GET', '/cats/{id}', $c['getCat'])
        ->register('PUT', '/cats/{id}', [
            $c['auth'],
            $c['jsonParser']
            $c['putCat']
        ])
        ->register('DELETE', '/cats/{id}', [
            $c['auth'],
            $c['deleteCat']
        ])
    )
);
$server->respond();

Features

PSR-7

Requests and responses are built to the interfaces standardized by PSR-7 making it easy to share code and use components from other libraries and frameworks.

Middleware

The middleware system guides requests through a sequence of discrete components. Add middleware to your Server for app-wide effect, or provide an array of middleware for an individual route.

Router

Use a router to map HTTP methods and paths to middleware. A router is a type of middleware, so you can branch a large router off into sub-routers.

URI Templates

Use URI templates like /foo/{bar}/{baz}, /list/{items*}, or {/path*} that match patterns of paths and provide captured variables.

Lazy Dispatching

WellRESTed's dispatcher can delay instantiating middleware until its needed, so even huge apps with lots of middleware can stay light weight.

Dependency Injection

WellRESTed does not supply a DI container; it's designed to play nicely with the container of your choice.

Installation

The recommended method for installing WellRESTed is to use the PHP dependency manager Composer. Add an entry for WellRESTed in your project’s composer.json file.

{
  "require": {
     "wellrested/wellrested": "^3.0"
  }
}

Requirements

Documentation

The documentaiton for WellRESTed is available at http://wellrested.readthedocs.io/