PHP code example of jyoungblood / xprss

1. Go to this page and download the library: Download jyoungblood/xprss library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jyoungblood / xprss example snippets



XPRSS\Application;
use XPRSS\Router;

$app = new Application();
$router = new Router();

$router->get('/', function($req, $res) {
	$res->send('<h1>Hello Cleveland!</h1>');
});

$app->listen($router);

$router = new Router();
$router->get('/', function($req, $res) {
    // This will be called when someone goes to the main page using GET method.
});

$router = new Router();
$router->get('/:something/:else', function($req, $res) {
    /**
     * Now let's imagine someone enters to URL: /hello/bye, then:
     *
     * $req->params->something will contain 'hello'
     * $req->params->else will contain 'bye'
     */
});

$router->post('/', function($req, $res) {
	$res->json(array(
		'error'		=> false,
		'message'	=> 'Hello'
	));
});

$router->post('/', function($req, $res) {
	$res->status(201)->json({
		'error'		=> false,
		'message'	=> 'Created!'
	});
});

// If you visit /static/image.png, this will return the file views/public/image.png
$router->use('/static', $app->static('views/public'));

// Configure the engine to Pug
$app->set('view engine','pug');

// Jade was renamed to Pug, but we recognize it ;)
$app->set('view engine','jade');

// Or Mustache
$app->set('view engine','mustache');

// Set the path to the template files
$app->set('views','./views/pug');

// Now you can do something like this
$router->get('/', function($req, $res) {
	$res->render('index.jade');
});

// Or this
$router->get('/users/:username', function($req, $res) {
	$res->render('index.jade', array(
		'name'	=> $req->params->username
	));

	// Now in jade, you can use #{name} to get that variable!
});

mermaid
  graph TD;
      A-->B;
      A-->C;
      B-->D;
      C-->E;
      A-->whatever
      whatever-->??;

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?route=$1 [L,QSA]

location / {
  if (!-e $request_filename){
    rewrite ^(.*)$ /index.php?route=$1 break;
  }
}