GithubHelp home page GithubHelp logo

http-server's Introduction

Mix Http Server

基于 Swoole 协程的 http server 类库,遵循 PSR-7 / PSR-15 标准

Usage

安装:

composer require mix/http-server

服务器:

  • 使用 handle 配置

'/' 将匹配所有路由

$server = new Mix\Http\Server\Server('0.0.0.0', 9596, false, false);
$server->handle('/', function (\Mix\Http\Message\ServerRequest $request, \Mix\Http\Message\Response $response) {
    $response->withBody(new \Mix\Http\Message\Stream\ContentStream('hello, world!'));
    $response->send();
});
$server->start();
  • 实现 HandlerInterface 接口
class Router implements \Mix\Http\Server\ServerHandlerInterface
{
    public function handleHTTP(ServerRequest $request, Response $response) {
        // ...
    }
}

$handler = new Router();

$server = new Mix\Http\Server\Server('0.0.0.0', 9596, false, false);
$server->start($handler);

中间件:

$process    = function (ServerRequest $request, Response $response) use ($result) {
    // ...
    return $response;
};
$dispatcher  = new MiddlewareDispatcher($middleware, $process, $request, $response);
$response    = $dispatcher->dispatch();

License

Apache License Version 2.0, http://www.apache.org/licenses/

http-server's People

Contributors

onanying avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

mix-plus

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.