{"id":16256488,"url":"https://github.com/janniks/restable","last_synced_at":"2025-03-19T21:31:03.472Z","repository":{"id":46413256,"uuid":"45279179","full_name":"janniks/Restable","owner":"janniks","description":"The probabaly tiniest PHP extensible micro-framework","archived":false,"fork":false,"pushed_at":"2021-10-15T12:13:26.000Z","size":13,"stargazers_count":4,"open_issues_count":1,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T23:26:14.689Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/janniks.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2015-10-30T22:11:54.000Z","updated_at":"2021-10-15T12:13:29.000Z","dependencies_parsed_at":"2022-09-23T00:20:28.206Z","dependency_job_id":null,"html_url":"https://github.com/janniks/Restable","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janniks%2FRestable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janniks%2FRestable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janniks%2FRestable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janniks%2FRestable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janniks","download_url":"https://codeload.github.com/janniks/Restable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244056428,"owners_count":20390720,"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":[],"created_at":"2024-10-10T15:45:22.223Z","updated_at":"2025-03-19T21:31:03.158Z","avatar_url":"https://github.com/janniks.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"This is a work in progress. ⚠️ That being said, even though Restable provides limited functionality compared to other frameworks, it is very stable and does what it is supposed to do. However, Restable is a toy project and not meant for production use.\n\n# Restable\nThe probabaly tiniest PHP extensible micro-framework there is.\n\nRemember this 'framework' is very tiny and has not been benchmarked, but should be very very fast.\n\n## Quick Start\nThe famous Hello World. Make sure to include the [`.htaccess`](./.htaccess).\n```php\n\u003c?php\n\nrequire_once 'Restable/Restable.php';\n$app = new Restable();\n\n$app-\u003eget('/', function() {\n    echo 'Hello World';\n});\n\n$app-\u003estart();\n```\n\nThat's it, that's the whole file! Now go to [`localhost`](http://localhost) or wherever you host your PHP and voilà.\n\n## [`.htaccess`](./.htaccess)\nUse this [`.htaccess`](./.htaccess) file to route everything to `index.php`. You can change the file you want to route to, by replacing the `index.php` with anything else.\n```\nRewriteEngine On\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteCond %{REQUEST_FILENAME} !-d\nRewriteRule ^(.*)$ index.php [QSA,L]\n```\n\n## Documentation\nFirst include the [*Restable source*](./Restable/Restable.php) and initialize *Restable* by creating a new instance. We will call it `app` for this documentation.\n```php\nrequire_once 'Restable/Restable.php';\n$app = new Restable();\n```\n\nAfter registering your routes make sure to `start` *Restable*.\n```php\n$app-\u003estart();\n```\n\n### Routes\n#### Registering Routes\nYou can use the `register` function to add a new route to be handled.\n```php\n$app-\u003eregister('GET', '/path', function() {\n    echo 'do something';\n});\n```\n\nThis is equivalent to the following.\n```php\nfunction some_function() {\n    echo 'do something';\n}\n\n$app-\u003eregister('GET', '/path', 'some_function');\n```\n\nYou can specify the `HTTP Method`, the `path`, and the `function` that will be executed.\n\n#### HTTP Method Shorthands\nYou also have a variety of shorthand register functions.\n\n* `get`\n* `post`\n* `put`\n* `delete`\n\nYou can use these shorthands just like the `$app-\u003eget()` in the Hello World tutorial.\n\n*e.g.* `post`\n```php\n$app-\u003epost('/user', function() {\n    echo 'add new user';\n});\n```\n\n### Parameters\nYou can parse parameters from the resource URL. Just add a `:` in the `path`.\n\n```php\n$app-\u003eput('/user/:user_id', function($user_id) {\n    echo 'update user ' . $user_id;\n});\n```\n\n### Hooks\nYou can easily extend your routes by adding hooks. There are `before` and `after` hooks. You can pass an array of hooks as an additional optional argument to the routing registration.\n\n```php\n$app-\u003eget('/secret', function() {\n    echo 'secret information';\n}, array(\n    'before' =\u003e function() {\n        if (!is_allowed_to_read_secrets()) {\n            echo 'Oops, you should\\'t see this... Bye bye!';\n            exit;\n        }\n    },\n));\n```\n\nYou can pass multiple hooks, even multiple hooks of the same kind.\n*e.g.* multiple `before` hooks and an `after` hook\n\n```php\nfunction include_config() {\n    require 'superFancyConfig.php';\n}\n\n$app-\u003eget('/secret', function() {\n    echo 'secret information';\n}, array(\n    'before' =\u003e 'include_config',\n    'before' =\u003e function() {\n        if (!is_allowed_to_read_secrets()) {\n            echo 'Oops, you should\\'t see this... Bye bye!';\n            exit;\n        }\n    },\n    'after' =\u003e function() {\n        echo 'this happens last';\n    },\n));\n```\n\n### Request \u0026 Response\n***TODO:** status, bad path, json, request path, etc. *\n\n## Todo\n- [x] Add simple JSON output\n- [ ] Add simple stats code\n- [ ] Add additional request and response types\n- [ ] Add multiple parameter capability\n- [ ] Add API blueprints\n- [ ] Add testing\n- [ ] Finish documentation\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanniks%2Frestable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanniks%2Frestable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanniks%2Frestable/lists"}