How can we create custom REST API route for sending specific data format to Android or IOS app ?
1 Answer
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.
-
Could you mention more about the shortcode such as "forgot_password" ? where do we put our arguments ?– Larry LoJan 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