Simple PHP Library for RESTful APIs
Go to file
Joe Ginley 17c58ae362 Added php minimum version badge and removed the requirements text.
Updated composer libraries, fixed phpunit errors after updating.
Updated docker-compose version.
Updated docker to use php 7.4.
2020-02-04 00:05:42 -05:00
docker Added php minimum version badge and removed the requirements text. 2020-02-04 00:05:42 -05:00
docs Fix link in documentation; fix version in README 2019-06-17 15:01:42 -04:00
public Update documentation for version 4.0 2018-06-26 16:51:33 -04:00
src Updated apache request headers to return if available, when false return empty array so nothing breaks. 2020-02-03 22:48:26 -05:00
test Added php minimum version badge and removed the requirements text. 2020-02-04 00:05:42 -05:00
.env Make local dev site port configurable 2018-06-21 12:48:11 -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 Added 7.4 to travis.yml. 2020-02-03 22:44:09 -05:00
README.md Added php minimum version badge and removed the requirements text. 2020-02-04 00:05:42 -05:00
composer.json Upgrade PHPUnit to v8 2019-06-17 16:04:55 -04:00
composer.lock Added php minimum version badge and removed the requirements text. 2020-02-04 00:05:42 -05:00
docker-compose.yml Added php minimum version badge and removed the requirements text. 2020-02-04 00:05:42 -05:00
phpunit.xml.dist Upgrade PHPUnit to v7 2018-06-21 10:20:33 -04:00

README.md

WellRESTed

Minimum PHP Version Build Status Documentation Status SensioLabsInsight

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

Install

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

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

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();

Development

Use Docker to run unit tests, manage Composer dependencies, and render a preview of the documentation site.

To get started, run:

docker-compose build
docker-compose run --rm php composer install

To run PHPUnit tests, use the php service:

docker-compose run --rm php phpunit

To generate documentation, use the docs service:

# Generate
docker-compose run --rm docs
# Clean
docker-compose run --rm docs make clean -C docs

To run a local playground site, use:

docker-compose up -d

The runs a site you can access at http://localhost:8080. You can use this site to browser the documentation or code coverage report.

Copyright © 2018 by PJ Dietz Licensed under the MIT license