Duplicate default endpoints
-
How can i duplicate default wp rest api V2 endpoints? I would like to keep default endpoints and routs intact, but would like to use simplified responses for my application.
My code for now:
// function register_custom_routes() { $controller = new MY_REST_Posts_Controller; $controller->register_routes(); } add_action( 'rest_api_init', 'register_custom_routes', 1 ); class MY_REST_Posts_Controller extends WP_REST_Controller { // this is a copy of default class WP_REST_Posts_Controller }
Calling
https://localhost/wp/wp-json/
list my namespace ( /myrest ), also
https://localhost/wp/wp-json/myrest/
gives me:{ "namespace": "myrest", "routes": { "/myrest": { "namespace": "myrest", "methods": [ "GET" ], ... ... "/myrest/(?P<id>[\\d]+)": { "namespace": "myrest", "methods": [ "GET", "POST", "PUT", "PATCH", "DELETE" ], ... ... }
but when i try to list posts with
https://localhost/wp/wp-json/myrest/posts
(like with default api route call) it does not wotk:{ "code": "rest_no_route", "message": "No route was found matching the URL and request method", "data": { "status": 404 } }
Please help. I need simplified version of get posts response for android app but also want to keep default rest endpoints and routs as is.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Duplicate default endpoints’ is closed to new replies.