nazg/http-server-request-handler

PSR-15 like HTTP Server Request Handler Interface

0.6.0 2020-03-31 07:56 UTC

This package is auto-updated.

Last update: 2024-11-04 21:21:44 UTC


README

PSR-15 Like HTTP Server Request Handlers Interface For Hack

Require

HHVM 3.30.0 and above.
required hsl-experimental

Install

$ hhvm $(which composer) require nazg/http-server-request-handler

Usage

Golang style

func middleware(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		log.Printf("Hello World, %s", r.RequestURI)
		next.ServeHTTP(w, r)
	}
}

For Hack

<?hh // strict

namespace Acme\Middleware;

use type HH\Lib\Experimental\IO\WriteHandle;
use type Facebook\Experimental\Http\Message\ResponseInterface;
use type Facebook\Experimental\Http\Message\ServerRequestInterface;
use type Nazg\Http\Server\MiddlewareInterface;
use type Nazg\Http\Server\RequestHandlerInterface;

final class ExampleMiddleware implements MiddlewareInterface {

  public function process(
    WriteHandle $writeHandle,
    ServerRequestInterface $request,
    RequestHandlerInterface $handler,
  ): ResponseInterface {
    return $handler->handle($write, $request);
  }
}