0

How can we create custom REST API route for sending specific data format to Android or IOS app ?

0

We can create route using rest_api_init action like :

Simply add below code to your theme functions.php file.

add_action( 'rest_api_init', function () {
    register_rest_route('wp/v2', 'forgot_password', array(
        'methods' => array('GET', 'POST'),
        'callback' => 'forgot_password'
    ));
} );

function forgot_password(){
    // YOUR CALLBACK FUNCTION STUFF HERE
}

forgot_password will define route URL address.

methods will define which method u want get request parameters like GET or POST.

callback will define callback function which is call when rest api will fire.

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.