-
Notifications
You must be signed in to change notification settings - Fork 191
Support Autodiscovery #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contains unit tests & integration tests, with ~85% coverage Closes #74 The API this provides is as follows: ```js var apiPromise = WP.discover( 'http://my-site.com' ); apiPromise.then(function( site ) { // If default routes were detected, they are now available site.posts().then(function( posts ) { console.log( posts ); }); // etc // If custom routes were detected, they can be accessed via .namespace() site.namespace( 'myplugin/v1' ).authors() .then(function( authors ) { /* ... */ }); // Namespaces can be saved out to variables: var myplugin = site.namespace( 'myplugin/v1' ); myplugin.authors().id( 7 ).then(function( author ) { /* ... */ }); }); ``` TODO: Readme documentation
The new version of Chai apparently considers errors not to be objects
Collaborator
Author
|
🐎 |
kadamwhite
added a commit
that referenced
this pull request
Jun 24, 2016
kadamwhite
added a commit
that referenced
this pull request
Jun 24, 2016
This release makes some key changes, adds some essential functionality, and re-wires things under the hood. I am unilaterally adopting the model of naming releases after albums, because I am releasing this in Vienna and "Mozart's House" by Clean Bandit (New Eyes, track 1) has been stuck in my head throughout WordCamp Europe. **Autodiscovery** Autodiscovery is now supported via the `WP.discover` method (#181) **Bootstrapping** If you already have the API response object you want to bootstrap with, the `.routes` property from it can now be passed in when calling `WP.site` or instantiating a `new WP` object (also #181, documented #182): ```js var site = WP.site( 'http://my-endpoint.com/wp-json', endpointJSON.routes ); ``` A script to ease the process of downloading this JSON object was added in PR #175 **registerRoute** Arbitrary methods for custom endpoints can now be added without auto- discovery by using the `.registerRoute` method, which takes the same route configuration strings as `register_rest_route` in the API core. **Internal Re-Architecture** In #168 the innards of the library were totally gutted and re-written to support autodiscovery, registerRoute and bootstrapping. **Human-Readable names for HTTP verbs** `PUT` and `POST` are not the most intuitive words for what they do, and POST in particular caused a lot of semantic confusion with the post object within the WordPress data model. `.post` has become `.create`, and `.put` has become `.update`. **Upgraded Dependencies** Package dependencies and developer tools have all been updated to the latest version in their respective ranges. **Props** @props to the community that submitted code, bugs, issues, questions, or comments that added to & informed this release. For general advice & conceptual validation: @rmccue For assisting with the discussion about how to handle autodiscovery and custom route endpoints: @adamsilverstein @aedensixty @andreipot @artoliukkonen @BenHen75 @chrishutchinson @elyobo @gnarf @ishaan-puniani @jasonphillips @joehoyle @jupitercow @timmyc For opening issues and asking questions: @aedensixty @dasheck0 @JSteranko @nabeards @satish9323 @stompweb We still owe responses to: @MurhafSousli @smedegaard @tommedema @vtripolitakis
kadamwhite
added a commit
that referenced
this pull request
Dec 5, 2016
In #181 auto-discovery was added that permits a consumer of this library to automatically locate the API root for a given WordPress site (specified by URL), and in most cases to automatically detect & initialize specific route handlers for the API routes available on that site. However, these methods were never updated to account for #221, which added the ability to replace the default HTTP transport (superagent) with a custom implementation or a wrapper. This meant that even if the consumer had specified their own transport, for example jQuery, there would still be a dependency on superagent should they wish to use the auto-discovery capabilities of the library. This PR updates the auto-discovery logic to use the same HTTP transport layer as the rest of the client, which has the added benefit of removing a number of duplicative logic that existed in the auto-discovery module.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contains unit tests & integration tests, with ~85% coverage
Closes #74
The API this provides is as follows: