WP-API / docs

The content for developer.wordpress.org/rest-api
https://developer.wordpress.org/rest-api
110 stars 615 forks source link

Backbone API docs seem incomplete and/or out of date #128

Open noknokcody opened 2 years ago

noknokcody commented 2 years ago

I've recently become super interested in using the backbone javascript client for some React-based settings pages but I'm finding it increasingly difficult to use. I feel like the documentation needs a bit of an update.

Specifically speaking this link here

Some of the problems I've noticed are as follows

Extending custom post types won't take the new URL root

Documentation specifies the following for custom post types

// Extend wp.api.models.Post and wp.api.collections.Posts to load a custom post type
const CustomPost = wp.api.models.Post.extend( {
  urlRoot: wpApiSettings.root + 'wp/v2/custom_post_slug',
  defaults: {
    type: 'custom_post_slug',
  },
} );

Yet when you extend the model and try save to the API it completely ignores the specified URL root.

image

Documentation relating to custom post type collections specifies an ambiguous type.

In the section relating to custom post type collections it mentions an ambiguous type 'BLProduct'. Is this supposed to be CustomPost?

const CustomPosts = wp.api.collections.Posts.extend( {
  url: wpApiSettings.root + 'wp/v2/custom_post_slug',
  model: BLProduct,
} );
const someCustomPosts = new CustomPosts();
someCustomPosts.fetch().then( ( posts ) => {
  // do something with the custom posts
} );

Some other minor issues I've discovered.

Backbone client seems like an extremely powerful and handy tool and I feel it really needs some attention and love from wordpress.