So I have created a custom endpoint using WP-API plugin. When testing with Postman, the endpoint works as expected.
The problem is that when I try to access the custom enpoint using the built in Backbone JS client, I cannot see my new endpoints in the wp.api.models object.
I have been digging and I think I have to send initialise it with a different schema or something, but have aboslutely no idea how to and can't find any info on how to extend wp.api.models so I can access my custom methods.
Example plugin code:
function my_awesome_func( $data ) {
return 'A STRING';
}
function initrest() {
register_rest_route( 'wp/v2', '/score', array(
'methods' => 'GET',
'callback' => 'my_awesome_func',
));
}
add_action( 'rest_api_init', 'initrest');
Example template code:
window.onload = function() {
console.log(wp.api.models);
};
This ouputs a list of the common models for Post, Comment, Tags etc, but no sign of my 'scores' endpoint.