/products这是一个路由,他可以由PUT,POST,GET,DELETE等这些操作
Router restAPI = Router.router(vertx); restAPI.get("/products/:productID").handler(rc -> { // TODO Handle the lookup of the product.... rc.response().write(productJSON); }); restAPI.put("/products/:productID").handler(rc -> { // TODO Add a new product... rc.response().end(); }); restAPI.delete("/products/:productID").handler(rc -> { // TODO delete the product... rc.response().end(); });
当他们作为顶级路由时,我们可以像这样/products/product1234 调用api
但是如果已经有了顶级路由
Router mainRouter = Router.router(vertx); // Handle static resources mainRouter.route("/static/*").handler(myStaticHandler); mainRouter.route(".*\\.templ").handler(myTemplateHandler);我们可以把这个路由追加到主路由后边,/productsAPI是主路由的化名。
mainRouter.mountSubRouter("/productsAPI", restAPI);这样restAPI路由就成了子路由,可以通过如下路径访问: /productsAPI/products/product1234