Title: GP routing &#8211; WP compatible REST API
Author: renemanqueros
Published: <strong>November 27, 2015</strong>
Last modified: November 27, 2015

---

Search plugins

This plugin **hasn’t been tested with the latest 3 major releases of WordPress**.
It may no longer be maintained or supported and may have compatibility issues when
used with more recent versions of WordPress.

![](https://s.w.org/plugins/geopattern-icon/gp-routing.svg)

# GP routing – WP compatible REST API

 By [renemanqueros](https://profiles.wordpress.org/renemanqueros/)

[Download](https://downloads.wordpress.org/plugin/gp-routing.zip)

 * [Details](https://wordpress.org/plugins/gp-routing/#description)
 * [Reviews](https://wordpress.org/plugins/gp-routing/#reviews)
 *  [Installation](https://wordpress.org/plugins/gp-routing/#installation)
 * [Development](https://wordpress.org/plugins/gp-routing/#developers)

 [Support](https://wordpress.org/support/plugin/gp-routing/)

## Description

Allows developers to create REST-ish API’s that have access to all of WordPress 
and its plug-ins objects.

### Usage

Install the plug-in as any other plug-in.
 Project is divided in two sets of files:

    ```
    * index.php - This is where you register routes and/or middleware.
    * routes/ - This is where you place your routes.
    ```

### Middleware

Middlewares are functions that will be executed on every call to the API, generally
used to validate parameters or
 transform requests before they reach routes, code
for middleware is structured like this:

    ```
    app::middleware(function () {
        doSomething();
    });
    ```

 * Middlewares run for every Verb and do not automatically assign $_POST or $_GET
   to any variable

### Routes

A route is where you would link a request to a function depending on its HTTP Verb.

The routing engine will prepend /api/ to all calls and will append a trailing slash
to all requests. A GET request would be matched like this:

    ```
    app::get('/testget', function($req){
       return $req;
    });
    ```

In which:

    ```
    * app::get - This will match up a GET request.
    * '/testget' - the path the routing engine will look for.
    * function(){ } ... - the function to execute when the route is matched.
    * $req - parameters sent to the verb.
    ```

To make a call to this route, the full path would be:

    ```
    http://www.mysite.com/api/testget/
    ```

 * The trailing slash is always required.
 * Parameters for all routes will be sent as the first parameter to the callback.

A route should be registered on the index file by placing a call to app::routes 
with the filename of the route (without the extension) as a parameter:

    ```
    app::routes('test');
    ```

 * All routes output their return value as a JSON encoded response.

### Samples for all verbs

 * GET:
 * app::get(‘/testget’, function($req){
    return $req; });
 * POST:
 * app::post(‘/testpost’, function($req){
    return $req; });
 * DELETE:
 * app::delete(‘/testdelete’, function($req){
    return $req; });
 * PUT:
 * app::put(‘/testput’, function($req){
    return $req; });

### Nested routes

Routes can be nested like this:

    ```
    app::delete('/admin/machines', function($req){
        return $req;
    });
    ```

Which could be called by issuing a DELETE to:

    ```
    http://www.mysite.com/api/admin/machines/<h3>Route and middleware registration</h3>
    Code for the routes should be placed on a file inside the "routes" folder and then "registered" on the index.php file like this:
    ```

function gp_registerapimethods()
 { app::middleware(function () {

    ```
    });

    app::routes('test');
    ```

}

Only one instance of the gp_registerapimethods should exist on the index.php file.

Middleware and Routes can have as many instances as needed. All routes inside the
routes folder can be registered by doing this call instead of the individual route
registration:

    ```
      app::routes('*');
      <h3>Sample for everything</h3> The index.php file has the "test" route registered, and that test.php route a call for each verb which you could use as a starting point for your own services.
    ```

## Installation

 1. Upload the contents of the zip file to the `/wp-content/plugins/` directory
 2. Activate the plugin through the ‘Plugins’ menu in WordPress

## Reviews

There are no reviews for this plugin.

## Contributors & Developers

“GP routing – WP compatible REST API” is open source software. The following people
have contributed to this plugin.

Contributors

 *   [ renemanqueros ](https://profiles.wordpress.org/renemanqueros/)

[Translate “GP routing – WP compatible REST API” into your language.](https://translate.wordpress.org/projects/wp-plugins/gp-routing)

### Interested in development?

[Browse the code](https://plugins.trac.wordpress.org/browser/gp-routing/), check
out the [SVN repository](https://plugins.svn.wordpress.org/gp-routing/), or subscribe
to the [development log](https://plugins.trac.wordpress.org/log/gp-routing/) by 
[RSS](https://plugins.trac.wordpress.org/log/gp-routing/?limit=100&mode=stop_on_copy&format=rss).

## Meta

 *  Version **1.0**
 *  Last updated **11 years ago**
 *  Active installations **Fewer than 10**
 *  WordPress version ** 3.0.1 or higher **
 *  Tested up to **4.3.34**
 * Tags
 * [api](https://wordpress.org/plugins/tags/api/)[rest](https://wordpress.org/plugins/tags/rest/)
 *  [Advanced View](https://wordpress.org/plugins/gp-routing/advanced/)

## Ratings

No reviews have been submitted yet.

[Your review](https://wordpress.org/support/plugin/gp-routing/reviews/#new-post)

[See all reviews](https://wordpress.org/support/plugin/gp-routing/reviews/)

## Contributors

 *   [ renemanqueros ](https://profiles.wordpress.org/renemanqueros/)

## Support

Got something to say? Need help?

 [View support forum](https://wordpress.org/support/plugin/gp-routing/)