PHP code example of awethemes / wp-http

1. Go to this page and download the library: Download awethemes/wp-http 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/ */

    

awethemes / wp-http example snippets




use Awethemes\Http\Kernel;
use Awethemes\Http\Request;

function my_plugin_register_routes( $router ) {
    $router->get( '/hello/{user}', function( Request $request, $user ) {
        return [ 'hello' => $user ];
    });
}

function my_plugin_dispatch() {
    global $wp;

    if ( empty( $wp->query_vars['my-route'] ) ) {
        return;
    }

    $kernel = new Kernel;
        ->use_request_uri( $wp->query_vars['my-route'] )
        ->use_dispatcher( \FastRoute\simpleDispatcher( 'my_plugin_register_routes' ) )
        ->handle( Request::capture() );
}
add_action( 'parse_request', 'my_plugin_dispatch' );