open kadamwhite/wordpress-rest-api#140

Can we call custom URL via node cilent?

andreipot

Hello @kadamwhite I'm using memberpress(https://www.memberpress.com/) which provides REST api as well. I've installed WP API v2 and on node side i'm using your client. However, member press API follows this format wp-json/mp/v1/members/:id whereas wordpress-rest-client follows this format wp-json/wp/v2/* At the moment, there is no way to point memberpress apis from your client, I can use HTTP request then there is authentication. is it possible for me to call memberpress rest api using this node client?

I think if we can manage to call custom URLs (not via post /page/ taxonomies ) then this is will be really awesome!

thanks, Andrei

kadamwhite

@andreipot As discussed in #138, there's currently not good support for this. The interface I have been hoping to implement would look like this:

var wp = require( 'wordpress-rest-api' ).site( 'http://your-site.com/wp-json' );

wp.members = wp.endpoint({
  collection: 'members',
  namespace: 'mp',
  version: 'v1'
});

wp.members().id( 7 )._renderURI(); // http://your-site.com/wp-json/mp/v1/members/7

I'd be curious for your thoughts about this interface.

kadamwhite

After discussion with @rmccue the string mp/v1 taken as a whole is the "namespace"; I have opened issue #141 to track removing the now-obsolete "version" method. Additionally, "base" is a more generic property name for defining a collection endpoint, in the event that a REST endpoint is created for a collection-less resource.

In light of these findings then the .endpoint method would be imagined to work as follows:

wp.members = wp.endpoint({
  base: 'members',
  namespace: 'mp/v1'
});
andreipot

@kadamwhite Awesome, I will test it and let you know. I think what you did is right.

andreipot

@kadamwhite for custom query request, rather than packing them as functions like wp.posts(), we'd rather have it accept custom URL led by namespace and base.

kadamwhite

@andreipot can you elaborate or provide an example to show what you mean?