basemaster / wellrested
Clone for Simple PHP Library for RESTful APIs (wellrested.org)
Requires
- php: >=7.2
- psr/http-factory: ~1.0
- psr/http-message: ~1.0
- psr/http-server-handler: ~1.0
- psr/http-server-middleware: ~1.0
Provides
- dev-master
- v5.1.1.2
- v5.1.1.1
- v5.0.1.1
- v5.0.1
- v5.0.0
- v4.0.5
- v4.0.5-RC2
- v4.0.5-RC1
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v4.0.0-RC4
- v4.0.0-RC3
- v4.0.0-RC2
- v4.0.0-RC
- v3.1.0
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v3.0.0-beta3
- v3.0.0-beta2
- v3.0.0-beta
- v2.3.0
- v2.3.0-alpha
- v2.2.1
- v2.2.0
- v2.1.0
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- dev-fix-extra-leading-slash-in-path
This package is not auto-updated.
Last update: 2024-12-13 17:43:17 UTC
README
WellRESTed is a library for creating RESTful APIs and websites in PHP that provides abstraction for HTTP messages, a powerful handler and middleware system, and a flexible router.
This fork (basemaster/wellrested) is back to php 7.2 release.
Features
- Uses PSR-7 interfaces for requests, responses, and streams. This lets you use other PSR-7 compatable libraries seamlessly with WellRESTed.
- Uses PSR-15 interfaces for handlers and middleware to allow sharing and reusing code
- Router allows you to match paths with variables such as
/foo/{bar}/{baz}
. - Middleware system provides a way to compose your application from discrete, modular components.
- Lazy-loaded handlers and middleware don't instantiate unless they're needed.
Install
Add an entry for "wellrested/wellrested" to your composer.json file's require
property.
{ "require": { "wellrested/wellrested": "^5" } }
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 instance. $server = new Server(); // Add a router to the server to map methods and endpoints to handlers. $router = $server->createRouter(); // Register the route GET / with an anonymous function that provides a handler. $router->register("GET", "/", function () { return new HomePageHandler(); }); // Add the router to the server. $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 run Psalm for static analysis:
docker-compose run --rm php psalm
To run PHP Coding Standards Fixer:
docker-compose run --rm php php-cs-fixer fix
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 and License
Copyright © 2020 by PJ Dietz Licensed under the MIT license