{"id":15170984,"url":"https://github.com/aeberdinelli/express-php","last_synced_at":"2025-10-01T06:31:44.009Z","repository":{"id":56941394,"uuid":"92697986","full_name":"aeberdinelli/express-php","owner":"aeberdinelli","description":"A framework built for learning purposes only, it clones the ExpressJS use writing style. Not recommended for production, use slim or any other actual framework instead :)","archived":true,"fork":false,"pushed_at":"2021-06-09T12:01:06.000Z","size":69,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-18T13:35:23.634Z","etag":null,"topics":["apache2","api","express","jade","php","pug","rest"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aeberdinelli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-29T01:34:04.000Z","updated_at":"2023-03-30T11:19:00.000Z","dependencies_parsed_at":"2022-08-21T02:10:21.855Z","dependency_job_id":null,"html_url":"https://github.com/aeberdinelli/express-php","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fexpress-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fexpress-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fexpress-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aeberdinelli%2Fexpress-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aeberdinelli","download_url":"https://codeload.github.com/aeberdinelli/express-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234837036,"owners_count":18894519,"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":["apache2","api","express","jade","php","pug","rest"],"created_at":"2024-09-27T08:42:38.110Z","updated_at":"2025-10-01T06:31:43.692Z","avatar_url":"https://github.com/aeberdinelli.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExpressPHP\nThis framework tries to clone the NodeJS [ExpressJS framework](https://www.npmjs.com/package/express) writing style. It does not have an event loop, it just mimics the method and helpers names that ExpressJS offers.\n\n## Install\n**Note**: To run ExpressPHP you need PHP \u003e= 7.0 and Apache.\n\nThe preferred installation is using Composer:\n\n`composer require aeberdinelli/express-php v1.1.0`\n\nThen, move the .htaccess to the root of your site and you're done:\n\n`mv vendor/aeberdinelli/express-php/.htaccess ./.htaccess`\n\n## Usage\nIf you installed using composer, you can just do:\n\n```php\n\u003c?php\ninclude __DIR__.'/vendor/autoload.php';\n\nuse Express\\Express;\nuse Express\\Router;\n\n$express = new Express();\n$router = new Router();\n\n$router-\u003eget('/', function($req, $res) {\n\t$res-\u003esend('hello world!');\n});\n\n$express-\u003elisten($router);\n?\u003e\n```\n\n## Routes\nRoutes are handled using a Router instance, for example:\n\n```php\n$router = new Router();\n$router-\u003eget('/', function($req, $res) {\n    // This will be called when someone goes to the main page using GET method.\n});\n```\n\nYou can handle post requests as well using post() instead of get(). Same for put() and delete().\n\n## Route with dynamic parameters\nYou can route dynamic URL using parameters, for example:\n\n```php\n$router = new Router();\n$router-\u003eget('/:something/:else', function($req, $res) {\n    /**\n     * Now let's imagine someone enters to URL: /hello/bye, then:\n     *\n     * $req-\u003eparams-\u003esomething will contain 'hello'\n     * $req-\u003eparams-\u003eelse will contain 'bye'\n     */\n});\n```\n\n## Responses\nIf you're developing an API for example, you can send json simply doing:\n\n```php\n$router-\u003epost('/', function($req, $res) {\n\t$res-\u003ejson(array(\n\t\t'error'\t\t=\u003e false,\n\t\t'message'\t=\u003e 'Hello'\n\t));\n});\n```\n\nYou can also send a custom http response code using:\n\n```php\n$router-\u003epost('/', function($req, $res) {\n\t$res-\u003estatus(201)-\u003ejson({\n\t\t'error'\t\t=\u003e false,\n\t\t'message'\t=\u003e 'Created!'\n\t});\n});\n```\n\n**TIP**: There are a few more examples in the `index.php` file in this repository.\n\n## Static files\nIf you wish to serve static files (likes images, html only) you can use:\n\n```php\n// If you visit /static/image.png, this will return the file views/public/image.png\n$router-\u003euse('/static', $express-\u003estatic('views/public'));\n```\n\n## Template engines\nYou have avaible [Pug](https://pugjs.org) (ex Jade) and [Mustache](https://mustache.github.io/). Here's an example:\n\n```php\n// Configure the engine to Pug\n$express-\u003eset('view engine','pug');\n\n// Jade was renamed to Pug, but we recognize it ;)\n$express-\u003eset('view engine','jade');\n\n// Or Mustache\n$express-\u003eset('view engine','mustache');\n\n// Set the path to the template files\n$express-\u003eset('views','./views/pug');\n\n// Now you can do something like this\n$router-\u003eget('/', function($req, $res) {\n\t$res-\u003erender('index.jade');\n});\n\n// Or this\n$router-\u003eget('/users/:username', function($req, $res) {\n\t$res-\u003erender('index.jade', array(\n\t\t'name'\t=\u003e $req-\u003eparams-\u003eusername\n\t));\n\n\t// Now in jade, you can use #{name} to get that variable!\n});\n\n```\n\n## CSS Precompilers\nYou can use Less instead of CSS if you want. An example:\n\n```php\nuse \\Express\\ExpressLess;\n\n/**\n * Let's say you have a /less folder on your project\n * And you want every request that goes into /css to load the less file within that folder instead\n *\n * In this example /css/global.css will load the compiled version of /less/global.less\n * Same for /css/something.css -\u003e /less/something.less\n */\n\n$less = new ExpressLess($express, array(\n\t'source'\t=\u003e __DIR__.'/less',\n\t'dest'\t\t=\u003e '/css'\n));\n\n// Yes, it's that simple.\n```\n\n## Request info\n- You have the body of the request in $res-\u003ebody no matter if you re handling POST or PUT.\n- You have the query string under $req-\u003equery\n- You have the cookies in $req-\u003ecookies\n- You have all the request headers in $req-\u003eheaders\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faeberdinelli%2Fexpress-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faeberdinelli%2Fexpress-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faeberdinelli%2Fexpress-php/lists"}