PHPackages                             haruncpi/wp-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. haruncpi/wp-api

ActiveLibrary[API Development](/categories/api)

haruncpi/wp-api
===============

An elegant WordPress REST API routing system

v1.0.1(2y ago)122642cc-by-4.0PHPPHP &gt;=7.1.0

Since Aug 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/haruncpi/wp-api)[ Packagist](https://packagist.org/packages/haruncpi/wp-api)[ RSS](/packages/haruncpi-wp-api/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

WP API
======

[](#wp-api)

 [![](https://camo.githubusercontent.com/01a1a117452a6379999a6eadf9cf59961b0c1897ce5bbfa2f2ac0f293041c9f3/68747470733a2f2f62616467656e2e6e65742f62616467652f6c6963656e63652f434320425920342e302f323342434342) ](https://creativecommons.org/licenses/by/4.0/)[![](https://camo.githubusercontent.com/9ba5289b19369ecabe353fee96db6e48ad127da96cb169ade1acac06fded1b1a/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f762f686172756e6370692f77702d617069)](https://packagist.org/packages/haruncpi/wp-api) ![](https://camo.githubusercontent.com/9a4290c3948870e4ec3a1e331c044162405d88f814e650eeed4c66ce60f9208b/68747470733a2f2f62616467656e2e6e65742f7061636b61676973742f64742f686172756e6370692f77702d617069)

An elegant WordPress REST API routing system.

[![WP API](wp-api.png)](wp-api.png)

Support
-------

[](#support)

[![Buy Me A Coffee](https://camo.githubusercontent.com/0cf29a542375e1a46e84d8bf5805a4e5c0a6ee98b6547ccdc0c55eed49d99c69/68747470733a2f2f63646e2e6275796d6561636f666665652e636f6d2f627574746f6e732f76322f64656661756c742d79656c6c6f772e706e67)](https://www.buymeacoffee.com/haruncpi)

Documentation
-------------

[](#documentation)

### Installation

[](#installation)

```
composer require haruncpi/wp-api

```

### Configuration

[](#configuration)

In your plugin init file, write this simple config code.

```
ApiConfig::set_route_file( __DIR__ . '/api-routes.php' )
		->set_namespace( 'MyPlugin\Api' )
		->init();
```

### Route Define

[](#route-define)

Open `api-routes.php` file and write route

Syntax

```
ApiRoute::get( $prefix, $endpoint, $callback, $auth = false );
ApiRoute::post( $prefix, $endpoint, $callback, $auth = false );

// Multiple route in a prefix group.
ApiRoute::prefix( $prefix, function( ApiRoute $route ) {
    $route->get( $endpoint, $callback, $auth = false );
    $route->post( $endpoint, $callback, $auth = false );
});
```

Where

- `$prefix` is your plugin name with api version. Example: `myplugin/v1`
- By default, `$auth` is false means the endpoint can be access without authentication.
- To make a endpoint `secure` pass a callback in the place of `$auth`

Example

```
ApiRoute::get( 'myplugin/v1', '/me', 'ApiController@me' );
```

Secure route

```
ApiRoute::get( 'myplugin/v1', '/me', 'ApiController@me', 'AuthController@check' );
```

### Various way to write callback.

[](#various-way-to-write-callback)

```
ApiRoute::get( 'myplugin/v1', '/me', 'ApiController@me' );
```

```
ApiRoute::get( 'myplugin/v1', '/me', array( ApiController:class, 'me' ) );
```

```
ApiRoute::get( 'myplugin/v1', '/me', array( 'MyPlugin\Api\ApiController', 'me' ) );
```

```
ApiRoute::get( 'myplugin/v1', '/me', function() {
    // Do something.
});
```

### Multiple route register

[](#multiple-route-register)

```
ApiRoute::prefix( 'myplugin/v1', function( ApiRoute $route ) {
    $route->get( '/products', 'ApiController@products' );
    $route->get( '/categories', 'ApiController@categories' );
});
```

### With auth check

[](#with-auth-check)

```
// With auth check
ApiRoute::prefix( 'myplugin/v1', function( ApiRoute $route ) {
    $route->get( '/me', 'ApiController@me' );
    $route->get( '/settings', 'ApiController@settings' );
    $route->post( '/logout', 'ApiController@logout' );
})->auth( 'AuthController@check' );
```

### Plugin Example

[](#plugin-example)

[API Plugin](https://github.com/haruncpi/api-plugin) is a WordPress example plugin for this composer package.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

 Bus Factor1

Top contributor holds 77.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~126 days

Total

2

Last Release

877d ago

PHP version history (2 changes)v1.0.0PHP &gt;=5.6.0

v1.0.1PHP &gt;=7.1.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ccb60a7a5a21d3f5ade112c82454c9ad6b7c8bace01b14f3715e47a2c86e8b7?d=identicon)[haruncpi](/maintainers/haruncpi)

---

Top Contributors

[![haruncpi](https://avatars.githubusercontent.com/u/11594794?v=4)](https://github.com/haruncpi "haruncpi (7 commits)")[![harunollyo](https://avatars.githubusercontent.com/u/97671808?v=4)](https://github.com/harunollyo "harunollyo (1 commits)")[![Maikuolan](https://avatars.githubusercontent.com/u/12571108?v=4)](https://github.com/Maikuolan "Maikuolan (1 commits)")

---

Tags

apiapi-libraryphprest-apiwordpresswordpress-packagewordpress-plugin-development

### Embed Badge

![Health badge](/badges/haruncpi-wp-api/health.svg)

```
[![Health](https://phpackages.com/badges/haruncpi-wp-api/health.svg)](https://phpackages.com/packages/haruncpi-wp-api)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M475](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M270](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M452](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
