Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mix-php/http-server
Http server library based on Swoole coroutine, following PSR-7 / PSR-15 standard
https://github.com/mix-php/http-server
http mix server
Last synced: 4 days ago
JSON representation
Http server library based on Swoole coroutine, following PSR-7 / PSR-15 standard
- Host: GitHub
- URL: https://github.com/mix-php/http-server
- Owner: mix-php
- Created: 2019-01-30T07:51:57.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-04-15T15:35:58.000Z (over 2 years ago)
- Last Synced: 2024-11-06T16:00:04.664Z (13 days ago)
- Topics: http, mix, server
- Language: PHP
- Homepage:
- Size: 66.4 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Mix Http Server
基于 Swoole 协程的 http server 类库,遵循 PSR-7 / PSR-15 标准
## Usage
安装:
- Swoole >= 4.4.4: https://wiki.swoole.com/#/environment
```
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/