1

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

1 Answer 1

1

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.

2
  • Could you mention more about the shortcode such as "forgot_password" ? where do we put our arguments ?
    – Larry Lo
    Jan 8, 2019 at 13:09
  • @RajuyourPepe this question is not for create shortcode so if you looking for create shortcode in wordpress then please check wordpress.stackexchange.com/questions/172919/… Jan 8, 2019 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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