PHPackages                             arafatkn/wrest - 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. arafatkn/wrest

ActiveLibrary[API Development](/categories/api)

arafatkn/wrest
==============

WREST - easy to use REST API wrapper for WordPress

0.0.1(3y ago)912MITPHPPHP &gt;=5.6

Since Mar 26Pushed 3y ago1 watchersCompare

[ Source](https://github.com/arafatkn/wrest)[ Packagist](https://packagist.org/packages/arafatkn/wrest)[ Docs](https://github.com/arafatkn/wrest)[ RSS](/packages/arafatkn-wrest/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelogDependencies (1)Versions (3)Used By (0)

[![WREST](https://camo.githubusercontent.com/5d2f0221d456e3aff41ccf7a62b3524cf807f8c4fe1d046f89953fd6ad522f60/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f57524553542e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6172616661746b6e2532467772657374267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d456173792b746f2b7573652b666c75656e742b524553542b4150492b777261707065722b666f722b576f726450726573732e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d636f6465)](https://camo.githubusercontent.com/5d2f0221d456e3aff41ccf7a62b3524cf807f8c4fe1d046f89953fd6ad522f60/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f57524553542e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6172616661746b6e2532467772657374267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d456173792b746f2b7573652b666c75656e742b524553542b4150492b777261707065722b666f722b576f726450726573732e266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d636f6465)

WREST (WordPress REST)
======================

[](#wrest-wordpress-rest)

WREST - easy to use fluent REST API wrapper for WordPress.

[![Latest Stable Version](https://camo.githubusercontent.com/4d00d39ebaadcf947f5a70edf964bfaf3d3b55fdf6245231cbfd912a8781b67e/68747470733a2f2f706f7365722e707567782e6f72672f6172616661746b6e2f77726573742f76)](https://camo.githubusercontent.com/4d00d39ebaadcf947f5a70edf964bfaf3d3b55fdf6245231cbfd912a8781b67e/68747470733a2f2f706f7365722e707567782e6f72672f6172616661746b6e2f77726573742f76)[![PHP Version Require](https://camo.githubusercontent.com/cc3816eeeec6b318dda59bbcb14f367d77d1d6e45c996b0388c7917df4b00b3e/687474703a2f2f706f7365722e707567782e6f72672f6172616661746b6e2f77726573742f726571756972652f706870)](https://packagist.org/packages/arafatkn/wrest)[![License](https://camo.githubusercontent.com/c9aac2c740aa08d7128c0b4b434a230eb11b2b0cc8d6e0bd24b327761ca0e02b/68747470733a2f2f706f7365722e707567782e6f72672f6172616661746b6e2f77726573742f6c6963656e7365)](https://camo.githubusercontent.com/c9aac2c740aa08d7128c0b4b434a230eb11b2b0cc8d6e0bd24b327761ca0e02b/68747470733a2f2f706f7365722e707567782e6f72672f6172616661746b6e2f77726573742f6c6963656e7365)[![Total Downloads](https://camo.githubusercontent.com/3321b7e5620998641a7edb17e8915c0b5b05c7b2c48f59787ac08c4035242909/68747470733a2f2f706f7365722e707567782e6f72672f6172616661746b6e2f77726573742f646f776e6c6f616473)](//packagist.org/packages/arafatkn/wrest)

Installation
------------

[](#installation)

### Requirements

[](#requirements)

- PHP &gt;= 5.6
- WordPress &gt;= 4.4

You can install wRest in two ways, via composer and manually.

### 1. Composer Installation

[](#1-composer-installation)

Add dependency in your project (theme/plugin):

```
composer require arafatkn/wrest

```

Now add `autoload.php` in your file if you haven't done already.

```
require __DIR__ . '/vendor/autoload.php';
```

### 2. Manual Installation

[](#2-manual-installation)

Not Available Yet.

Usage
-----

[](#usage)

WordPress API needs a namespace, so you have to set a namespace first.

One way is to set a default namespace before creating routes.

```
wrest()->setNamespace('my-plugin/v1');

wrest()->get('hello', function() {
    return 'Hello world';
});
```

or you can set namespace for a group of routes.

```
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';
    });
});
```

Passed callback will get a `WP_REST_Request` object as a parameter.

```
wrest()->get('greeting', function(WP_REST_Request $req) {
    return 'Hello world';
});
```

#### More Examples

[](#more-examples)

```
wrest()->get('posts', $callback);
wrest()->post('posts', [$postController, 'store']);
wrest()->put($uri, $callback);
wrest()->patch($uri, $callback);
wrest()->delete($uri, $callback);
wrest()->any($uri, $callback); // All Routes GET, POST, PUT, PATCH, DELETE
wrest()->match(['GET', 'POST'], $uri, $callback);
```

### Permission Management

[](#permission-management)

Passing a capability

```
wrest()->get('greeting', function() {
    return 'Hello world';
})->permission('manage_options');
```

Passing a callback

```
wrest()->get('greeting', function() {
    return 'Hello world';
})->permission(function(WP_REST_Request $req) {
    return is_user_logged_in();
});
```

### Parameters passing

[](#parameters-passing)

```
wrest()->get('/posts/{slug}', function(WP_REST_Request $request, $slug) {
    //
})->param('slug', '[A-Za-z]+');

wrest()->get('/user/{id}/{name}', function ($request, $id, $name) {
    //
})->param('id', '[0-9]+')->param('name', '[a-z]+');

wrest()->get('/user/{id}/{name}', function ($request, $id, $name) {
    //
})->param(['id' => '[0-9]+', 'name' => '[a-z]+']);
```

If you do not pass a regex for a param then `[^/]+` will be used as default.

```
wrest()->get('/posts/{slug}', function(WP_REST_Request $request, $slug) {
    // Also Works. slug will contain all the characters between posts/ and next /.
});
```

### Route Action

[](#route-action)

Action can be a callback, a class method, a static class method or a non-static class method and can be passed as below.

```
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.
```

All the functions will get a `WP_REST_Request` object as a parameter.

Supported Features
------------------

[](#supported-features)

- Namespaces for All Routes.
- Normal Routes.
- Routes with Parameters.
- Route Actions.
- Permission Management.

#### Upcoming Features

[](#upcoming-features)

- Add support for route groups.
- Add support for namespace on the fly.
- Add support for namespace groups.
- Add support for resource routes.
- Add support for schema.
- Add support route redirection.
- Add support for passing matched parameters directly to actions.

Credits
-------

[](#credits)

Special thanks to [Tareq Hasan](https://gist.github.com/tareq1988/be49697425326fc90952de835313ff6b) for this awesome idea.

Contribution Guide
------------------

[](#contribution-guide)

This is still in beta, though I have a confidence that it will work as expected. You can contribute by reporting bugs, fixing bugs, reviewing pull requests and more ways. Go to [**issues**](https://github.com/arafatkn/wrest/issues) section, and you can start working on a issue immediately. If you want to add or fix something, open a pull request.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

1145d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e90f2bf40704413c963340fe5500aff02fe57b99faae6b1c0a984ba83e759a1?d=identicon)[arafatkn](/maintainers/arafatkn)

---

Top Contributors

[![arafatkn](https://avatars.githubusercontent.com/u/80309866?v=4)](https://github.com/arafatkn "arafatkn (13 commits)")

---

Tags

wordpresswpwp-restwp-rest-apiwp-rest-apiwordpress-rest-apiwp-restwp rest api wrapper

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/arafatkn-wrest/health.svg)

```
[![Health](https://phpackages.com/badges/arafatkn-wrest/health.svg)](https://phpackages.com/packages/arafatkn-wrest)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

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

A PHP wrapper for Twilio's API

1.6k92.9M272](/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.1M454](/packages/google-gax)

PHPackages © 2026

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