Giter VIP home page Giter VIP logo

http's Introduction

HTTP

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 [email protected] or create a Security Advisory instead of using the issue tracker.

License

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

http's People

Contributors

ghostwriter avatar

Stargazers

 avatar  avatar

Watchers

 avatar

http's Issues

Tokens

class RequestLineToken extends Token {}
class MethodToken extends Token {}
class UriToken extends Token {}
class HttpVersionToken extends Token {}
class CrlfToken extends Token {}
class HeaderToken extends Token {}
class FieldNameToken extends Token {}
class FieldValueToken extends Token {}
class SpToken extends Token {}
class OwsToken extends Token {}
class HtabToken extends Token {}
class VcharToken extends Token {}
class ObsTextToken extends Token {}
class FieldContentToken extends Token {}
class MessageBodyToken extends Token {}

HTTP/3 Response

:status: 200
content-type: text/html; charset=UTF-8
content-encoding: gzip
cache-control: private, max-age=0
set-cookie: UserID=JohnDoe; Max-Age=3600; Secure; HttpOnly
server: Apache/2.4.46 (Unix) OpenSSL/1.1.1k
date: Sat, 24 Mar 2023 15:46:23 GMT
:push-promise: <style.css>
:push-promise: <script.js>

<HTML content>

Features:

  • Other headers like HTTP/1.1 response #13
  • Other headers like HTTP/2 response #14
  • Server push using :push-promise pseudo-header with resources to be pushed to the client

HTTP/2 Response

HTTP/2 200 OK
date: Sat, 24 Mar 2023 15:46:23 GMT
content-type: text/html; charset=UTF-8
content-encoding: gzip
cache-control: private, max-age=0
set-cookie: UserID=JohnDoe; Max-Age=3600; Secure; HttpOnly
server: Apache/2.4.46 (Unix) OpenSSL/1.1.1k
link: </style.css>; rel=preload; as=style
link: </script.js>; rel=preload; as=script
:status: 200

<HTML content>

Features:

  • :status pseudo-header indicating the status code and message: 200 OK
  • Other headers like HTTP/1.1 response #13
  • Link header specifying the server push resources

HTTP/1.1 Response

HTTP/1.1 200 OK
Date: Sat, 24 Mar 2023 15:46:23 GMT
Content-Type: text/html; charset=UTF-8
Content-Encoding: gzip
Expires: -1
Cache-Control: private, max-age=0
Set-Cookie: UserID=JohnDoe; Max-Age=3600; Secure; HttpOnly
Server: Apache/2.4.46 (Unix) OpenSSL/1.1.1k

<HTML content>

Features:

  • Status code and message: 200 OK
  • Date header
  • Content-Type header specifying the MIME type of the response body
  • Content-Encoding header indicating that the response body has been compressed using gzip
  • Expires header indicating that the response should not be cached
  • Cache-Control header with directives for cache control
  • Set-Cookie header to set a cookie for the client
  • Server header specifying the server software and its version

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.