humanmade/mercator-rest-api

REST API endpoint for Mercator.

Installs: 1

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 24

Forks: 2

Open Issues: 4

Type:wordpress-muplugin

dev-master 2018-12-04 17:13 UTC

This package is auto-updated.

Last update: 2024-04-05 06:02:08 UTC


README

REST API for working with domain mappings.

Requires WordPress 4.5+ or the WP REST API plugin

Usage

You need to include and instantiate the controller:

add_action( 'rest_api_init', function() {
    include 'class-rest-api.php';
    $api = new Mercator\REST_API;
    $api->register_routes();
} );

The controller adds two API routes:

/wp-json/mercator/v1/mappings       // accepts GET, POST
/wp-json/mercator/v1/mappings/:id   // accepts PUT, PATCH, DELETE

You can additionally specify a blog ID by passing in a GET parameter:

/wp-json/mercator/v1/mappings?blog=1

Data structure

Mappings are very simple. The example JSON object for a mapping is as follows:

{
    "id": 1                       // integer
    "domain": "example.com",      // string
    "active": true                // boolean
}

When creating a mapping using POST you only need to send the domain and active values.