Opened 8 years ago
Closed 7 years ago
#39683 closed defect (bug) (fixed)
REST API JS Client: Should enable connecting to multiple endpoints at the same time
Reported by: | adamsilverstein | Owned by: | adamsilverstein |
---|---|---|---|
Milestone: | 4.7.5 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | has-patch has-unit-tests commit |
Focuses: | javascript, rest-api | Cc: |
Description
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.
Attachments (2)
Change History (19)
#1
@
8 years ago
- Keywords has-patch needs-unit-tests added
- Milestone changed from Awaiting Review to 4.8
#2
follow-up:
↓ 3
@
8 years ago
@adamsilverstein Wanted to let you know that this seems to resolve the problems.
#3
in reply to:
↑ 2
@
8 years ago
Replying to lucasstark:
@adamsilverstein Wanted to let you know that this seems to resolve the problems.
Great! Thank you for testing.
This ticket was mentioned in Slack in #core-restapi by adamsilverstein. View the logs.
8 years ago
#6
@
8 years ago
39683.2.diff adds a unit test to verify multiple endpoints work correctly
#10
@
8 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
@jnylen0 that would make sense if there is still time. reopening for consideration, cc: @swissspidy
This ticket was mentioned in Slack in #core-restapi by adamsilverstein. View the logs.
8 years ago
This ticket was mentioned in Slack in #core by desrosj. View the logs.
8 years ago
#15
follow-up:
↓ 16
@
8 years ago
- Resolution set to fixed
- Status changed from reopened to closed
This was only open for backporting, so closing back out now that focus has switched to 4.8.
#16
in reply to:
↑ 15
@
7 years ago
- Milestone changed from 4.8 to 4.7.5
- Resolution fixed deleted
- Status changed from closed to reopened
Replying to rmccue:
This was only open for backporting, so closing back out now that focus has switched to 4.8.
I don't think this ever made it into 4.7.4, can we get this merged to 4.7.5? I'd like to fix this bug for people using WordPress 4.7.
cc: @swissspidy
39683.diff
Correct a name collision issue that prevented the client from properly connecting to multiple APIs as it was designed to do.
versionString
andapiRoot
findWhere
as per coding standardsdeferred.resolve
call - only pass the resolvedEndpoint, not the wp.api globalI'd like to add a QUnit test here to demonstrate/verify the fix by connecting to two known remote apis.