HTTP Client and Server abstraction for PHP.

dev-main 2024-07-17 19:48 UTC

This package is auto-updated.

Last update: 2024-10-17 20:25:00 UTC


README

Compliance Supported PHP Version GitHub Sponsors Code Coverage Type Coverage Latest Version on Packagist Downloads

HTTP Client and Server abstraction for PHP.

Warning

This project is not finished yet, work in progress.

Installation

You can install the package via composer:

composer require ghostwriter/http

Usage

$router = new Router();

$router->addRoute('GET', '/', HomeHandler::class, [GuestMiddleware::class]);

$router->get('/about', AboutHandler::class, [GuestMiddleware::class]);

$router->get('/auth/github', GitHubLoginHandler::class, [GuestMiddleware::class], 'auth.login.github');

    // create, read, edit, update, store, delete, view, show 
$router->middleware([GuestMiddleware::class], function($router){
    $router->get('/auth/login', LoginCreateHandler::class, 'auth.login.create');
    $router->post('/auth/login', LoginStoreHandler::class, 'auth.login.store');

    $router->get('/auth/register', RegisterCreateHandler::class, 'auth.register.create');
    $router->post('/auth/register', RegisterStoreHandler::class, 'auth.register.store');

    $router->get('/posts', PostIndexHandler::class, 'members.index');
    $router->get('/posts/{post:id}', PostShowHandler::class, 'members.show');
});

$router->middleware([AuthMiddleware::class], function($router){
    $router->get('/users', MembersIndexHandler::class, 'members.index');
    $router->get('/users/{member:id}', MemberShowHandler::class, 'members.show');

    $router->get('/posts/create', PostCreateHandler::class, 'members.create');
    $router->post('/posts', PostStoreHandler::class, 'members.store');
    $router->get('/posts/{post:id}/edit', PostEditHandler::class, 'members.edit');
    $router->put('/posts/{post:id}', PostUpdateHandler::class, 'members.update');
    $router->delete('/posts/{post:id}', PostDeleteHandler::class, 'members.delete');
});

$request = new ServerRequest();

$server = new Server($router); // RequestHandler

$server->handle($request); // Response

Changelog

Please see CHANGELOG.md for more information what has changed recently.

Security

If you discover any security related issues, please email nathanael.esayeas@protonmail.com or create a Security Advisory instead of using the issue tracker.

License

The BSD-3-Clause. Please see License File for more information.