1. Go to this page and download the library: Download arafatkn/wrest 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/ */
wrest()->usingNamespace('my-plugin/v1', function($wrest) {
// You can use both $wrest or wrest() here
$wrest->get('greeting', function(WP_REST_Request $req) {
return 'Hello world';
});
});
wrest()->get('/posts/{slug}', function(WP_REST_Request $request, $slug) {
// Also Works. slug will contain all the characters between posts/ and next /.
});
wrest()->get('posts', function() => {});
wrest()->get('posts', 'getAllPosts'); // getAllPosts is a function.
wrest()->get('posts', 'PostController@getAll'); // getAll is static function.
wrest()->get('pages', [$pageController, 'getAll']); // getAll is non-static function.
wrest()->get('authors', [CommentController::class, 'getAll']); // getAll is static function.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.