[wp-trac] [WordPress Trac] #39683: REST API JS Client: Should enable connecting to multiple endpoints at the same time

WordPress Trac noreply at wordpress.org
Tue Jan 24 22:33:28 UTC 2017


#39683: REST API JS Client: Should enable connecting to multiple endpoints at the
same time
----------------------------------+-----------------------------
 Reporter:  adamsilverstein       |      Owner:
     Type:  defect (bug)          |     Status:  new
 Priority:  normal                |  Milestone:  Awaiting Review
Component:  REST API              |    Version:  4.7
 Severity:  normal                |   Keywords:
  Focuses:  javascript, rest-api  |
----------------------------------+-----------------------------
 Originally from @lucasstark: https://github.com/WP-API/client-
 js/issues/145

  If you need to talk to more than one endpoint the way the api is
 initialized does not make this straight forward.
  -
  It seems like it should be possible, since wp.api.endpoints is a
 collection of each unique endpoint you might initialize, however, the
 collections and models on each endpoint will be overwritten each time you
 call wp.api.init, so obviously we need a solid way to initialize more than
 one endpoint at once.
  -
  An example use case would be in a multisite environment you might want to
 talk to two of the subsites at the same time.
  -
  You'd think you could do something like this rough example:

 {{{
     var sites = [];

     wp.api.init({
         'apiRoot': 'http://example.com/subsite1/wp-json/'
     }).done(function(endpoint){
         sites[ 1 ] = endpoint;
     });

     wp.api.init({
         'apiRoot': 'http://example.com/subsite2/wp-json/'
     }).done(function(endpoint){
         sites[ 2 ] = endpoint;
     });
 }}}
  But now sites[1].collections is configured with the URL for the second
 site.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39683>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list