First we need to add the following code to our functions.php.

add_action('rest_api_init', function () {
    register_rest_route('namespace', '/path', [
        'methods' => 'GET',
        'callback' => function () {
            return $_GET;
        }
    ]);
});

Then we can create a simple form and process the request via Javascript.

$('form').on('submit', function (e) {
    e.preventDefault();

    $.ajax({
        type: 'GET',
        url: '/wp-json/namespace/path',
        data: $('form').serialize()
    }).done(function (response) {
        console.log(response);
    });
});

Alternatively, you can also call the following URL directly in the browser:
https://www.domain.com/wp-json/namespace/path?parameter=value

Leave a Reply

Your email address will not be published. Required fields are marked *