Simple PHP Library for RESTful APIs
Go to file
PJ Dietz 473d103739 Documentation proofreading 2018-03-13 13:23:15 -04:00
docker Add local development example site. 2018-03-12 15:05:19 -04:00
docs Documentation proofreading 2018-03-13 13:23:15 -04:00
public Add local development example site. 2018-03-12 15:05:19 -04:00
src Update draft PSR-15 interfaces 2018-03-12 15:05:19 -04:00
test Update draft PSR-15 interfaces 2018-03-12 15:05:19 -04:00
.gitattributes Add .gitattributes to remove non-essentials files from dist 2015-05-15 19:27:18 -04:00
.gitignore Add local development example site. 2018-03-12 15:05:19 -04:00
.travis.yml Update Travis to test using PHP 7.1 to meet dependency requirements for tests. 2017-08-03 14:09:40 -04:00
README.md Update README with PSR-15 interface 2018-03-12 15:05:19 -04:00
composer.json Add official PSR-15 interfaces via composer 2018-03-12 15:05:19 -04:00
composer.lock Add official PSR-15 interfaces via composer 2018-03-12 15:05:19 -04:00
docker-compose.yml Add local development example site. 2018-03-12 15:05:19 -04:00
phpunit.xml.dist Add local development example site. 2018-03-12 15:05:19 -04:00

README.md

WellRESTed

Build Status Documentation Status SensioLabsInsight

WellRESTed is a library for creating RESTful Web services and websites in PHP.

Requirements

  • PHP 7.0

Install

Add an entry for "wellrested/wellrested" to your composer.json file's require property.

{
    "require": {
        "wellrested/wellrested": "~3.1"
    }
}

Documentation

See the documentation to get started.

Example

<?php

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use WellRESTed\Message\Response;
use WellRESTed\Message\Stream;
use WellRESTed\Server;

// Create a handler using the PSR-15 RequestHandlerInterface
class HomePageHandler implements RequestHandlerInterface
{
    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        // Create and return new Response object to return with status code,
        // headers, and body.
        $response = (new Response(200))
            ->withHeader('Content-type', 'text/html')
            ->withBody(new Stream('<h1>Hello, world!</h1>'));
        return $response;
    }
}

// -----------------------------------------------------------------------------

// Create a new server.
$server = new Server();

// Add a router to the server to map methods and endpoints to handlers.
$router = $server->createRouter();
$router->register('GET', '/', new HomePageHandler());
$server->add($router);

// Read the request from the client, dispatch a handler, and output.
$server->respond();

Copyright © 2018 by PJ Dietz Licensed under the MIT license