@Override
public Router createGlobalRouter() {
Router router = Router.router(vertx());
router.route("/hello").handler(rc -> {
rc.response().end("world");
});
return router;
}
You can extend the REST API by adding the RestPlugin
interface to your plugin class.
You can now implement two different methods to extend the REST API at different places in the API.
You can hook your plugin routes to the /api/v1/plugins
endpoint.
Implementing the createGlobalRouter
method as shown below would add the /api/v1/plugins/hello-world/hello
endpoint for the plugin with the hello-world
restApiName.
@Override
public Router createGlobalRouter() {
Router router = Router.router(vertx());
router.route("/hello").handler(rc -> {
rc.response().end("world");
});
return router;
}
The method createGlobalRouter will be invoked multiple times in order to register the endpoints to all request handlers.
|
Additionally you can also hook your plugin routes to the /api/v1/:projectName/plugins
endpoint.
Implementing the createProjectRouter
method as shown below would add the /api/v1/:projectName/plugins/hello-world/hello-project
endpoint for the plugin to all projects.
@Override
public Router createProjectRouter() {
Router router = Router.router(vertx());
router.route("/hello-project").handler(rc -> {
rc.response().end("world");
});
return router;
}
The method createProjectRouter will be invoked multiple times in order to register the endpoints to all request handlers.
|
The Vert.x RoutingContext
contains information which can be accessed by the plugin.
The project context can be wrapped via wrap(rc)
to get the PluginContext
which makes it possible to access various information.
Method | Description |
---|---|
|
Return |
|
Return the project name. |
|
Return a new client which can be used to access the API . This client will in contrast to |
router.route("/projectInfo").handler(rc -> {
PluginContext context = wrap(rc);
rc.response().end(context.project().encodePrettily());
});
You can read more about the Vert.x router API in the Vert.x Web documentation.