rest services made easy
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

restServer - rest services made easy

restServer provides

  • a PSR HTTP message rest server
  • builtin ip, cors, auth, serializing and decoding mgnt
  • API for your application


To install with composer:

composer require kigkonsult/restserver

Requires PHP 5.6, 7.*


Example usage:


require '/path/to/vendor/autoload.php';

// Implement an application rest service operation entry
// (or any callable with the same interface)
$callback = function(
    ServerRequestInterface $request,
    ResponseInterface      $response
) {
    return $response->withRawBody( [ 'Hello' => 'world' ] );

// Set up the rest service definition (method, uri and callback)
$restGetServiceDef = [
    RestServer::METHOD   => RequestMethodHandler::METHOD_GET,
    RestServer::URI      => '/',
    RestServer::CALLBACK => $callback

// Attach the rest service(s) and fire of the server
RestServer::factory()->attachRestService( $restGetServiceDef )->run();

More example usage:


require '/path/to/vendor/autoload.php';

$RestServer = new RestServer();

$attachRestServiceCallback = $RestServer->getAttachRestServiceCallback();

class ApplicationClass2
    public function registerAsRestService(
    ) {
            [$this, 'action']

    public function action(
        ServerRequestInterface $request,
        ResponseInterface      $response
    ) {
        return $response->withRawBody( ['msg' => 'Hello world'] );

$ApplicationClass2 = new ApplicationClass2();
$ApplicationClass2->registerAsRestService( $attachRestServiceCallback );


Rest service definition

You have to implement one or more rest service (callable) entries for your application logic. Each entry with one or more http request methods and a (single) uri (ex '/') form a service definition. The service definitions, attached to restServer, are interfaces to your application logic.


restServer have builtin handlers managing IPnumber validation, Cross-Origin Resource Sharing, authentication, messages serializing and en-/decoding. As well as rest service definitions, you can attach custom request message handler(s), invoked before any operation callback. Also a custom (single) final handler can be attached, invoked after response is returned.


In the restServer package docs folder are found

  • summary and supplementary documentation
  • demo applications and service definitions
  • demo handlers
  • more examples

For restServer issues, use github. Due to the restServer development status (ver 0.9.123), review reports are appreciated!

Credits and base software information

Built status

Dev 0.9.123