i am using wordpress JetPack JSON API to serve a self-hosted site posts to a mobile app. i need to serve a basic key-value dictionary from the same site admin panel to manipulate some settings in the mobile app as well. any easy way of doing that ?


You could create your own WP REST API endpoint that handles this. To register a custom endpoint:

add_action( 'init', 'bootstrap_api' );

function bootstrap_api() {
    add_action( 'rest_api_init', 'my_api_endpoint' );

function my_api_endpoint() {
    register_rest_route('myapi/v1', 'get/words', array(
        'methods' => 'GET',
        'callback' => 'return_word_list',
    ) );

function return_word_list() {
    // Do someting to build your list of words...
    // $words = get_my_words();
    $words = array(
        'key' => 'value',
        'foo' => 'bar',
        'baz' => 'blah',
        // etc

    return $words;

Then, when you visit /wp-json/myapi/v1/get/words, you'll see something like this:

    "key": "value",
    "foo": "bar",
    "baz": "blah"

This is quite barebones, and I'm not sure what you'll need to do in terms of the Jetpack JSON stuff for authentication, but it should get you off on the right path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.