{"id":26824897,"url":"https://github.com/freeelephants/rest-daemon","last_synced_at":"2025-04-28T14:05:16.508Z","repository":{"id":62507231,"uuid":"75711034","full_name":"FreeElephants/rest-daemon","owner":"FreeElephants","description":"Micro framework for building REST applications on http-socket server","archived":false,"fork":false,"pushed_at":"2019-12-15T14:21:39.000Z","size":237,"stargazers_count":4,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-28T14:05:10.763Z","etag":null,"topics":["middleware","php-daemon","php-framework","rest-api","rest-server","socket-server"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FreeElephants.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-06T08:31:08.000Z","updated_at":"2019-11-10T21:52:41.000Z","dependencies_parsed_at":"2022-11-02T12:30:55.836Z","dependency_job_id":null,"html_url":"https://github.com/FreeElephants/rest-daemon","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeElephants%2Frest-daemon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeElephants%2Frest-daemon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeElephants%2Frest-daemon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FreeElephants%2Frest-daemon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FreeElephants","download_url":"https://codeload.github.com/FreeElephants/rest-daemon/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251326836,"owners_count":21571634,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["middleware","php-daemon","php-framework","rest-api","rest-server","socket-server"],"created_at":"2025-03-30T10:18:09.126Z","updated_at":"2025-04-28T14:05:16.488Z","avatar_url":"https://github.com/FreeElephants.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rest-Daemon\n\n[![Build Status](https://travis-ci.org/FreeElephants/rest-daemon.svg?branch=master)](https://travis-ci.org/FreeElephants/rest-daemon) [![codecov](https://codecov.io/gh/FreeElephants/rest-daemon/branch/master/graph/badge.svg)](https://codecov.io/gh/FreeElephants/rest-daemon) [![Installs](https://img.shields.io/packagist/dt/free-elephants/rest-daemon.svg)](https://packagist.org/packages/free-elephants/rest-daemon) [![Releases](https://img.shields.io/packagist/v/free-elephants/rest-daemon.svg)](https://github.com/FreeElephants/rest-daemon/releases)\n\n**Nota Bene:**\nThis project uses semver and [changelog](CHANGELOG.md).\nBut it's not a stable major version.\nAny minor update (f.e. 0.5.* -\u003e 0.6.*) can break backward compatibility!\n\nSimple PHP7 framework for fast building REST services based on middleware, PSR-7 and react.\n\nRunned instance can be found by [link](http://rest-daemon-example.samizdam.net:8080/uptime), also see [example repo](https://github.com/FreeElephants/rest-daemon-example).\n\n## Features:\n\n- Middleware oriented request/response handling\n- Priority PSR's support: PSR-2, -3, -4, -7, -11, -15 and other. \n- Built-in Middleware to support usual REST features, like HTTP based semantics, content types, request parsing, headers. \n- Choose one of two available http-daemon drivers: Ratchet [ReactPHP](https://github.com/ratchetphp/Ratchet) or [Aerys](https://github.com/amphp/aerys). \n- [Swagger Integration](/docs/SWAGGER.md)\n\n## Installation \n\n    $ composer require free-elephants/rest-daemon\n\n## Usage\n\nSee example in example/rest-server.php and [documentation](/docs/INDEX.md). \n\n### Create and Run Server:\n\n```\n# your rest-server.php script\n$server = new RestServer('127.0.0.1', 8080, '0.0.0.0', ['*']); // \u003c- it's default arguments values\n$server-\u003erun();\n\n# can be runned as\n$ php ./rest-server.php \n```\n\n### Add Your RESTful API Endpoints\n\nAny endpoint method handler can be Middleware-like callable implementation: function or class with __invoke() method.  \n```php\n\u003c?php\nclass GetAttributeHandler extends AbstractEndpointMethodHandler\n{\n\n    public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)\n    {\n        $name = $request-\u003egetAttribute('name', 'World');\n        $response-\u003egetBody()-\u003ewrite('{\n            \"hello\": \"' . $name . '!\"\n        }');\n        return $next($request, $response);\n    }\n}\n\n$greetingAttributeEndpoint = new BaseEndpoint('/greeting/{name}', 'Greeting by name in path');\n$greetingAttributeEndpoint-\u003esetMethodHandler('GET', new GetAttributeHandler());\n\n$server-\u003eaddEndpoint($greetingAttributeEndpoint);\n```\n\nSee how to [build server for step by step in one script](/example/rest-server-script-example.php)\n\n### RestServerBuilder\n\nYou can use [php-di](https://github.com/free-elephants/php-di) (or another PSR-11 container implementation) and routing file configuration with RestServerBuilder for more configuring and coding less. \n\nSee example with file based [routing](/example/routes.php) and [dependencies](/example/components.php) configuration: [rest-server.php](/example/rest-server.php)  \n\n### Routing\nYou can link with every method in route a handler, and optionally organize routes by modules.  By default server contain 1 default module for all endpoints. \nSee example: [routes.php](/example/routes.php)\n\n### Configure Common Application Middleware\n\nBy default server instance provide collection with some useful middleware. \nYou can extend or override it: \n```php\n\u003c?php\n$requestCounter = function (\n    ServerRequestInterface $request,\n    ResponseInterface $response,\n    callable $next\n) {\n    static $requestNumber = 0;\n    printf('[%s] request number #%d handled' . PHP_EOL, date(DATE_ISO8601), ++$requestNumber);\n\n    return $next($request, $response);\n};\n$extendedDefaultMiddlewareCollection = new DefaultEndpointMiddlewareCollection([], [$requestCounter]);\n$server-\u003esetMiddlewareCollection($extendedDefaultMiddlewareCollection);\n```\n\nEvery endpoint's method handler will be wrapped to this collection and called between defined as `after` and `before` middleware. \nAlso you can configure default middleware collection with access to every built-in middleware by key: this collection implements ArrayAccess interface. \n```php\n\u003c?php\n$server-\u003egetMiddlewareCollection()-\u003egetBefore()-\u003eoffsetUnset(\\FreeElephants\\RestDaemon\\Middleware\\MiddlewareRole::NO_CONTENT_STATUS_SETTER);\n```\n\n### Customize Endpoint Middleware\n... _Will be implemented..._\n\n### Debugging and Logging\n... _Will be implemented..._\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeelephants%2Frest-daemon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffreeelephants%2Frest-daemon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffreeelephants%2Frest-daemon/lists"}