awethemes / wp-http
The Missing WordPress HTTP Foundation
Installs: 2 049
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 3
Forks: 2
Open Issues: 0
Requires
- php: >=5.5.9
- symfony/http-foundation: ^2.0|3.3.*
- tightenco/collect: 5.2.*|5.3.*|5.4.*
Requires (Dev)
- awethemes/wp-session: ^1.1
- mockery/mockery: ^0.9
- symfony/debug: ^2.0|^3.3
Suggests
- awethemes/wp-session: Missing session handler for WordPress
README
Provide HTTP Request & Response for WordPress inspired by Laravel.
Examples
<?php 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' );
Test your route:
> curl -X GET "http://yoursite.dev/index.php?my-route=/hello/david"
{"hello":"david"}