-
Notifications
You must be signed in to change notification settings - Fork 846
Jetpack API package #12513
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
Jetpack API package #12513
Conversation
|
Caution: This PR has changes that must be merged to WordPress.com |
This is an automated check which relies on |
2c68f18 to
026451e
Compare
|
We've merged this into the feature branch already: |
tyxla
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be interesting to deal with cases where endpoints rely on functionality that's not there. For example, the sync status endpoint would require the sync package; how would we behave if the sync package isn't here? Should we define an endpoint that returns an error, or not define it at all? Should we require sync package as a dependency of this one? 🤔
| "url": "./packages/*" | ||
| "url": "./packages/*", | ||
| "options": { | ||
| "symlink": true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, could we remove this? Ideally, we should be symlinking by default but mirroring for production.
What about each package registering their own endpoints? when the package is not present we could just 404 |
|
This approach is stale. Closing. |
In order to provide Jetpack API endpoints to other plugins, we move these files into a package.
The near-term goal is to have VaultPress able to connect and sync.
We aim to achieve this as follows:
Step 1: Move API files into package
In this step, we attempt to modify as little code as possible, but simply to make the API available in the package.
$loader->loadClass( 'WPCOM_JSON_API_Some_Endpoint' );(for each class that was in the file)Step 2: Virtualise API
Currently the REST API has to load the code for every API class, even though on any given request only one of those classes will actually be used to respond. This fills up the opcache with unneeded classes. Many APIs are actually never (or rarely) used, plus requiring them all foregoes the benefits of autoloading itself.
In order to virtualise the API, we need to change the pattern by which endpoints are registered. Currently the pattern is this:
This requires the endpoint class to be defined. Instead, we should have a way of registering an endpoint along with the class responsible for servicing these requests, but only load the class itself if the request is known to be for that class.
This may require something like:
The "Virtual" endpoint would instantiate the class on the fly if the incoming request is a POST to
'/sites/%s/something'Step 3: Separate endpoint definitions from implementations
We may not want to ship all our API implementations with every plugin. Yet, we should still be able to differentiate between an API which doesn't exist at all, vs one which requires a package that the plugin didn't include.
This will allow us to both ship less code to plugins, and have API clients be smarter about what they tell the user. For example, if VaultPress includes just a handful of APIs, and a site doesn't have Jetpack, Calypso should be able to function properly and simply hide, warn, etc. for endpoints that are not present on the site. Worst case scenario, it could tell the user that in order to display some screen, they need to install the Jetpack plugin.