{"id":20261389,"url":"https://github.com/haruncpi/wp-api","last_synced_at":"2025-04-11T01:45:15.545Z","repository":{"id":187453124,"uuid":"676916966","full_name":"haruncpi/wp-api","owner":"haruncpi","description":"An elegant WordPress REST API routing system","archived":false,"fork":false,"pushed_at":"2023-12-15T05:43:57.000Z","size":900,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T22:51:24.204Z","etag":null,"topics":["api","api-library","php","rest-api","wordpress","wordpress-package","wordpress-plugin-development"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/haruncpi.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-10T10:00:52.000Z","updated_at":"2025-03-02T17:19:38.000Z","dependencies_parsed_at":"2023-08-10T14:26:38.445Z","dependency_job_id":"0e432f01-a5b8-4bef-9790-815e351d269a","html_url":"https://github.com/haruncpi/wp-api","commit_stats":null,"previous_names":["haruncpi/wp-api"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haruncpi%2Fwp-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haruncpi%2Fwp-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haruncpi%2Fwp-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/haruncpi%2Fwp-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/haruncpi","download_url":"https://codeload.github.com/haruncpi/wp-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248327863,"owners_count":21085258,"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":["api","api-library","php","rest-api","wordpress","wordpress-package","wordpress-plugin-development"],"created_at":"2024-11-14T11:25:29.624Z","updated_at":"2025-04-11T01:45:15.524Z","avatar_url":"https://github.com/haruncpi.png","language":"PHP","readme":"\u003ch1 align=\"center\"\u003eWP API\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://creativecommons.org/licenses/by/4.0/\"\u003e\u003cimg src=\"https://badgen.net/badge/licence/CC BY 4.0/23BCCB\" /\u003e\n    \u003ca href=\"https://packagist.org/packages/haruncpi/wp-api\"\u003e\u003cimg src=\"https://badgen.net/packagist/v/haruncpi/wp-api\" /\u003e\u003c/a\u003e\n    \u003c/a\u003e\n    \u003ca href=\"\"\u003e\u003cimg src=\"https://badgen.net/packagist/dt/haruncpi/wp-api\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003eAn elegant WordPress REST API routing system.\u003c/p\u003e\n\n![WP API](wp-api.png)\n\n## Support\n\u003ca href=\"https://www.buymeacoffee.com/haruncpi\" target=\"_blank\"\u003e\u003cimg src=\"https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png\" alt=\"Buy Me A Coffee\" style=\"width: 160px !important;\" \u003e\u003c/a\u003e\n\n## Documentation\n\n### Installation\n```\ncomposer require haruncpi/wp-api\n```\n\n### Configuration\nIn your plugin init file, write this simple config code.\n```php\nApiConfig::set_route_file( __DIR__ . '/api-routes.php' )\n\t\t-\u003eset_namespace( 'MyPlugin\\Api' )\n\t\t-\u003einit();\n```\n\n### Route Define\n\nOpen `api-routes.php` file and write route\n\nSyntax\n```php\nApiRoute::get( $prefix, $endpoint, $callback, $auth = false );\nApiRoute::post( $prefix, $endpoint, $callback, $auth = false );\n\n// Multiple route in a prefix group.\nApiRoute::prefix( $prefix, function( ApiRoute $route ) {\n    $route-\u003eget( $endpoint, $callback, $auth = false );\n    $route-\u003epost( $endpoint, $callback, $auth = false );\n});\n```\nWhere\n- `$prefix` is your plugin name with api version.\nExample: `myplugin/v1`\n- By default, `$auth` is false means the endpoint can be access without authentication.\n- To make a endpoint `secure` pass a callback in the place of `$auth`\n\n\nExample\n```php\nApiRoute::get( 'myplugin/v1', '/me', 'ApiController@me' );\n```\nSecure route\n```php\nApiRoute::get( 'myplugin/v1', '/me', 'ApiController@me', 'AuthController@check' );\n```\n\n### Various way to write callback.\n```php\nApiRoute::get( 'myplugin/v1', '/me', 'ApiController@me' );\n```\n```php\nApiRoute::get( 'myplugin/v1', '/me', array( ApiController:class, 'me' ) );\n```\n```php\nApiRoute::get( 'myplugin/v1', '/me', array( 'MyPlugin\\Api\\ApiController', 'me' ) );\n```\n```php\nApiRoute::get( 'myplugin/v1', '/me', function() {\n    // Do something.\n});\n```\n\n### Multiple route register\n```php\nApiRoute::prefix( 'myplugin/v1', function( ApiRoute $route ) {\n    $route-\u003eget( '/products', 'ApiController@products' );\n    $route-\u003eget( '/categories', 'ApiController@categories' );\n});\n```\n\n### With auth check\n```php\n// With auth check\nApiRoute::prefix( 'myplugin/v1', function( ApiRoute $route ) {\n    $route-\u003eget( '/me', 'ApiController@me' );\n    $route-\u003eget( '/settings', 'ApiController@settings' );\n    $route-\u003epost( '/logout', 'ApiController@logout' );\n})-\u003eauth( 'AuthController@check' );\n```\n\n### Plugin Example\n[API Plugin](https://github.com/haruncpi/api-plugin) is a WordPress example plugin for this composer package.\n","funding_links":["https://www.buymeacoffee.com/haruncpi"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharuncpi%2Fwp-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharuncpi%2Fwp-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharuncpi%2Fwp-api/lists"}