{"id":14955111,"url":"https://github.com/arafatkn/wrest","last_synced_at":"2025-10-24T07:30:48.147Z","repository":{"id":147823315,"uuid":"523361598","full_name":"arafatkn/wrest","owner":"arafatkn","description":"WREST - easy to use fluent REST API wrapper for WordPress","archived":false,"fork":false,"pushed_at":"2023-04-02T07:51:34.000Z","size":31,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-01-29T08:34:00.120Z","etag":null,"topics":["wordpress","wp","wp-rest","wp-rest-api"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/arafatkn/wrest","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/arafatkn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-10T13:48:21.000Z","updated_at":"2024-06-28T09:01:46.000Z","dependencies_parsed_at":"2023-06-19T16:24:45.041Z","dependency_job_id":null,"html_url":"https://github.com/arafatkn/wrest","commit_stats":{"total_commits":11,"total_committers":2,"mean_commits":5.5,"dds":0.09090909090909094,"last_synced_commit":"2c4fa414270bc8b08e6fb74e0231aca1cb9c490c"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arafatkn%2Fwrest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arafatkn%2Fwrest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arafatkn%2Fwrest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arafatkn%2Fwrest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arafatkn","download_url":"https://codeload.github.com/arafatkn/wrest/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237932067,"owners_count":19389560,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["wordpress","wp","wp-rest","wp-rest-api"],"created_at":"2024-09-24T13:10:32.090Z","updated_at":"2025-10-24T07:30:47.815Z","avatar_url":"https://github.com/arafatkn.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![WREST](https://banners.beyondco.de/WREST.png?theme=light\u0026packageManager=composer+require\u0026packageName=arafatkn%2Fwrest\u0026pattern=architect\u0026style=style_1\u0026description=Easy+to+use+fluent+REST+API+wrapper+for+WordPress.\u0026md=1\u0026showWatermark=0\u0026fontSize=100px\u0026images=code)\n\n# WREST (WordPress REST)\nWREST - easy to use fluent REST API wrapper for WordPress.\n\n![Latest Stable Version](https://poser.pugx.org/arafatkn/wrest/v)\n[![PHP Version Require](http://poser.pugx.org/arafatkn/wrest/require/php)](https://packagist.org/packages/arafatkn/wrest)\n![License](https://poser.pugx.org/arafatkn/wrest/license)\n[![Total Downloads](https://poser.pugx.org/arafatkn/wrest/downloads)](//packagist.org/packages/arafatkn/wrest)\n\n## Installation\n\n### Requirements\n- PHP \u003e= 5.6\n- WordPress \u003e= 4.4\n\nYou can install wRest in two ways, via composer and manually.\n\n### 1. Composer Installation\n\nAdd dependency in your project (theme/plugin):\n\n```\ncomposer require arafatkn/wrest\n```\n\nNow add `autoload.php` in your file if you haven't done already.\n\n```php\nrequire __DIR__ . '/vendor/autoload.php';\n```\n\n### 2. Manual Installation\n\nNot Available Yet.\n\n## Usage\nWordPress API needs a namespace, so you have to set a namespace first.\n\nOne way is to set a default namespace before creating routes.\n```php\nwrest()-\u003esetNamespace('my-plugin/v1');\n\nwrest()-\u003eget('hello', function() {\n    return 'Hello world';\n});\n```\n\nor you can set namespace for a group of routes.\n```php\nwrest()-\u003eusingNamespace('my-plugin/v1', function($wrest) {\n    // You can use both $wrest or wrest() here\n    $wrest-\u003eget('greeting', function(WP_REST_Request $req) {\n        return 'Hello world';\n    });\n});\n```\n\nPassed callback will get a `WP_REST_Request` object as a parameter.\n\n```php\nwrest()-\u003eget('greeting', function(WP_REST_Request $req) {\n    return 'Hello world';\n});\n```\n\n#### More Examples\n\n```php\nwrest()-\u003eget('posts', $callback);\nwrest()-\u003epost('posts', [$postController, 'store']);\nwrest()-\u003eput($uri, $callback);\nwrest()-\u003epatch($uri, $callback);\nwrest()-\u003edelete($uri, $callback);\nwrest()-\u003eany($uri, $callback); // All Routes GET, POST, PUT, PATCH, DELETE\nwrest()-\u003ematch(['GET', 'POST'], $uri, $callback);\n```\n\n### Permission Management\n\nPassing a capability\n\n```php\nwrest()-\u003eget('greeting', function() {\n    return 'Hello world';\n})-\u003epermission('manage_options');\n```\n\nPassing a callback\n```php\nwrest()-\u003eget('greeting', function() {\n    return 'Hello world';\n})-\u003epermission(function(WP_REST_Request $req) {\n    return is_user_logged_in();\n});\n```\n\n### Parameters passing\n\n```php\nwrest()-\u003eget('/posts/{slug}', function(WP_REST_Request $request, $slug) {\n    //\n})-\u003eparam('slug', '[A-Za-z]+');\n\nwrest()-\u003eget('/user/{id}/{name}', function ($request, $id, $name) {\n    //\n})-\u003eparam('id', '[0-9]+')-\u003eparam('name', '[a-z]+');\n\nwrest()-\u003eget('/user/{id}/{name}', function ($request, $id, $name) {\n    //\n})-\u003eparam(['id' =\u003e '[0-9]+', 'name' =\u003e '[a-z]+']);\n```\n\nIf you do not pass a regex for a param then `[^/]+` will be used as default.\n\n```php\nwrest()-\u003eget('/posts/{slug}', function(WP_REST_Request $request, $slug) {\n    // Also Works. slug will contain all the characters between posts/ and next /.\n});\n```\n\n### Route Action\n\nAction can be a callback, a class method, a static class method or a non-static class method and can be passed as below.\n\n```php\nwrest()-\u003eget('posts', function() =\u003e {});\nwrest()-\u003eget('posts', 'getAllPosts'); // getAllPosts is a function.\nwrest()-\u003eget('posts', 'PostController@getAll'); // getAll is static function.\nwrest()-\u003eget('pages', [$pageController, 'getAll']); // getAll is non-static function.\nwrest()-\u003eget('authors', [CommentController::class, 'getAll']); // getAll is static function.\n```\nAll the functions will get a `WP_REST_Request` object as a parameter.\n\n## Supported Features\n- [x] Namespaces for All Routes.\n- [x] Normal Routes.\n- [x] Routes with Parameters.\n- [x] Route Actions.\n- [x] Permission Management.\n\n#### Upcoming Features\n- [ ] Add support for route groups.\n- [ ] Add support for namespace on the fly.\n- [ ] Add support for namespace groups.\n- [ ] Add support for resource routes.\n- [ ] Add support for schema.\n- [ ] Add support route redirection.\n- [ ] Add support for passing matched parameters directly to actions.\n\n## Credits\nSpecial thanks to [Tareq Hasan](https://gist.github.com/tareq1988/be49697425326fc90952de835313ff6b) for this awesome idea.\n\n## Contribution Guide\n\nThis is still in beta, though I have a confidence that it will work as expected.\nYou can contribute by reporting bugs, fixing bugs, reviewing pull requests and more ways.\nGo to [**issues**](https://github.com/arafatkn/wrest/issues) section, and you can start working on a issue immediately.\nIf you want to add or fix something, open a pull request.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farafatkn%2Fwrest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farafatkn%2Fwrest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farafatkn%2Fwrest/lists"}