Download the PHP package aeberdinelli/express-php without Composer
On this page you can find all versions of the php package aeberdinelli/express-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aeberdinelli/express-php
More information about aeberdinelli/express-php
Files in aeberdinelli/express-php
Package express-php
Short Description A clone of the ExpressJS Framework for PHP
License
Informations about the package express-php
ExpressPHP
This framework tries to clone the NodeJS ExpressJS framework writing style. It does not have an event loop, it just mimics the method and helpers names that ExpressJS offers.
Install
Note: To run ExpressPHP you need PHP >= 7.0 and Apache.
The preferred installation is using Composer:
composer require aeberdinelli/express-php v1.1.0
Then, move the .htaccess to the root of your site and you're done:
mv vendor/aeberdinelli/express-php/.htaccess ./.htaccess
Usage
If you installed using composer, you can just do:
Routes
Routes are handled using a Router instance, for example:
You can handle post requests as well using post() instead of get(). Same for put() and delete().
Route with dynamic parameters
You can route dynamic URL using parameters, for example:
Responses
If you're developing an API for example, you can send json simply doing:
You can also send a custom http response code using:
TIP: There are a few more examples in the index.php
file in this repository.
Static files
If you wish to serve static files (likes images, html only) you can use:
Template engines
You have avaible Pug (ex Jade) and Mustache. Here's an example:
CSS Precompilers
You can use Less instead of CSS if you want. An example:
Request info
- You have the body of the request in $res->body no matter if you re handling POST or PUT.
- You have the query string under $req->query
- You have the cookies in $req->cookies
- You have all the request headers in $req->headers