Improve parameter support & support mixins w/ registerRoute#229
Merged
kadamwhite merged 14 commits intomasterfrom Sep 23, 2016
Merged
Improve parameter support & support mixins w/ registerRoute#229kadamwhite merged 14 commits intomasterfrom
kadamwhite merged 14 commits intomasterfrom
Conversation
I am modifying wpapi-vagrant-varietal, the VM environment against which these integration tests are run, to include some custom post types and taxonomies. This change will prevent that commit from breaking these integration tests because it switches to validating that what we expect to be there is there, not that it is the only content available.
This eliminates all of the tests using the legacy approach of validating the integration between our library and superagent, instead of testing the actual public service of the library's methods
- Meta endpoint has been superseded by register_meta functionality - Auth has moved into the HTTP Transport object - Pages do not have comment support
Also (and unrelatedly, mea culpa) removes the functionality of `.context()` which would set authentication when called with "edit"; it is not the responsibility of the client to enforce authentication, that's the API's job
registerRoute now takes an optional `param` array on its configuration
object; this array can contain strings that will trigger existing mixins
(like `filter` to be applied to the generated handler:)
```js
site.handler = site.registerRoute( 'myplugin/v1', 'collection/(?P<id>)', {
// Listing any of these parameters will assign the built-in
// chaining method that handles the parameter:
params: [ 'filter', 'before', 'after', 'author', 'parent', 'post' ]
});
// yields
site.handler().forPost( 8 ).author( 92 ).filter( 'etc', 'etera' )...
```
but if the `params` array contains a parameter name string that does not
map to an existing parameter setter, a basic setter for that parameter
will be auto-generated:
```js
site.books = site.registerRoute( 'myplugin/v1', 'books/(?P<id>)', {
params: [ 'genre' ]
});
// yields "myplugin/v1/books?genre[]=19&genre[]=2000"
site.books().genre([ 19, 2000 ]).toString()
```
Full changes:
- Add support for all the most common first-party query parameters
(where commonality is a function of number of routes on which the
parameter can be used successfully):
+ `_embed`, `context`, `exclude`, `include`, `offset`, `order`,
`orderby`, `page`, `perPage`, `search`, and `slug` are supported
wherever WPRequests are sold (closes #178)
- Add ability to apply existing mixins to `registerRoute`-registered
handler methods by referencing the parameter name (fixes #203)
- Add ability to auto-generate a basic `.param()` convenience wrapper
for any given query parameter when using `registerRoute`
- Document `.param` method & its derivatives (fixes #226)
- Pork-Barrel the addition of a 404 page to the docs site
- Remove skipped test blocks for deprecated methods
- Clean up and standardize several test files
- Resolve some general docs issues
This was referenced Sep 23, 2016
Collaborator
Author
|
Lots of moving parts in this, but not as many as it seems:
|
edygar
approved these changes
Sep 23, 2016
Contributor
edygar
left a comment
There was a problem hiding this comment.
Nice 👍 ! That solves all the doubts I had, mostly involving the customRoutes and params/mixins and the best practice to use default mixins! Congrats and thank you!
Contributor
|
Awesome - thanks! |
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
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.
registerRoute now takes an optional
paramarray on its configuration object; this array can contain strings that will trigger existing mixins (likefilterto be applied to the generated handler:)but if the
paramsarray contains a parameter name string that does not map to an existing parameter setter, a basic setter for that parameter will be auto-generated:Full changes:
_embed,context,exclude,include,offset,order,orderby,page,perPage,search, andslugare supported wherever WPRequests are sold (closes Support all generally-supported query parameters in WPRequest itself #178)registerRoute-registeredhandler methods by referencing the parameter name (fixes Question: filtering custom content types? #203)
.param()convenience wrapperfor any given query parameter when using
registerRoute.parammethod & its derivatives (fixes Documentation of.param()#226)