}); router.delete("/api/users/:id").handler(ctx -> { mongo.findOne("users", new JsonObject().put("_id", ctx.request().getParam("id")), null, lookup -> {
router.delete("/users/:id").handler(ctx -> {
@Override public io.vertx.ext.web.Route delete() { return delegate.delete(); }
@Override public Route delete() { return router.delete(); }
@Override public Route delete(String path) { return router.delete(path); }
@Test public void testDelete() throws Exception { router.delete().handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.DELETE, "/whatever", 200, "foo"); testRequest(HttpMethod.GET, "/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/whatever", 404, "Not Found"); testRequest(HttpMethod.PUT, "/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/whatever", 404, "Not Found"); }
@Test public void testDeleteWithPathBegin() throws Exception { router.delete("/somepath/*").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.DELETE, "/somepath/whatever", 200, "foo"); testRequest(HttpMethod.DELETE, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.PUT, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }
@Test public void testDeleteWithPathExact() throws Exception { router.delete("/somepath/").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.DELETE, "/somepath/", 200, "foo"); testRequest(HttpMethod.DELETE, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.PUT, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }
/** * Add a route that matches any HTTP DELETE request * @return the route */ public io.vertx.rxjava.ext.web.Route delete() { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.delete()); return ret; }
/** * Add a route that matches a HTTP DELETE request and the specified path * @param path URI paths that begin with this path will match * @return the route */ public io.vertx.rxjava.ext.web.Route delete(String path) { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.delete(path)); return ret; }
/** * Add a route that matches any HTTP DELETE request * @return the route */ public io.vertx.rxjava.ext.web.Route delete() { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.delete()); return ret; }
/** * Add a route that matches a HTTP DELETE request and the specified path * @param path URI paths that begin with this path will match * @return the route */ public io.vertx.rxjava.ext.web.Route delete(String path) { io.vertx.rxjava.ext.web.Route ret = io.vertx.rxjava.ext.web.Route.newInstance(delegate.delete(path)); return ret; }
@Override public io.vertx.ext.web.Route delete(String path) { return delegate.delete(getFullPath(path)); }
@Override public Router createRouter(Vertx vertx) { this.vertx = vertx; store = new RxStore(StoreFactory.createStore(vertx)); storagePath = vertx.getOrCreateContext().config() .getString(ConfigConstants.STORAGE_FILE_PATH); Router router = Router.router(vertx); router.get("/*").handler(this::onGet); router.put("/*").handler(this::onPut); router.post("/*").handler(this::onPost); router.delete("/*").handler(this::onDelete); return router; }
@Override public void addRoutes(final Router router) { final String path = String.format("/%s", TenantConstants.TENANT_ENDPOINT); final BodyHandler bodyHandler = BodyHandler.create(); bodyHandler.setBodyLimit(config.getMaxPayloadSize()); // ADD tenant router.post(path).handler(bodyHandler); router.post(path).handler(this::extractRequiredJsonPayload); router.post(path).handler(this::checkPayloadForTenantId); router.post(path).handler(this::addTenant); final String pathWithTenant = String.format("/%s/:%s", TenantConstants.TENANT_ENDPOINT, PARAM_TENANT_ID); // GET tenant router.get(pathWithTenant).handler(this::getTenant); // UPDATE tenant router.put(pathWithTenant).handler(bodyHandler); router.put(pathWithTenant).handler(this::extractRequiredJsonPayload); router.put(pathWithTenant).handler(this::updateTenant); // REMOVE tenant router.delete(pathWithTenant).handler(this::removeTenant); }
@Override public void start(Future<Void> future) throws Exception { super.start(); Router router = Router.router(vertx); // body handler router.route().handler(BodyHandler.create()); // API route handler router.post(API_SAVE).handler(this::apiSave); router.get(API_RETRIEVE).handler(this::apiRetrieve); router.delete(API_CLOSE).handler(this::apiClose); // get HTTP host and port from configuration, or use default value String host = config().getString("store.http.address", "0.0.0.0"); int port = config().getInteger("store.http.port", 8085); createHttpServer(router, host, port) .compose(serverCreated -> publishHttpEndpoint(SERVICE_NAME, host, port)) .setHandler(future.completer()); }
@Test public void testDelete() throws Exception { router.delete().handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.DELETE, "/whatever", 200, "foo"); testRequest(HttpMethod.GET, "/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/whatever", 404, "Not Found"); testRequest(HttpMethod.PUT, "/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/whatever", 404, "Not Found"); }
@Test public void testDeleteWithPathExact() throws Exception { router.delete("/somepath/").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.DELETE, "/somepath/", 200, "foo"); testRequest(HttpMethod.DELETE, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.PUT, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }
@Test public void testDeleteWithPathBegin() throws Exception { router.delete("/somepath/*").handler(rc -> rc.response().setStatusMessage("foo").end()); testRequest(HttpMethod.DELETE, "/somepath/whatever", 200, "foo"); testRequest(HttpMethod.DELETE, "/otherpath/whatever", 404, "Not Found"); testRequest(HttpMethod.GET, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.POST, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.PUT, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.OPTIONS, "/somepath/whatever", 404, "Not Found"); testRequest(HttpMethod.HEAD, "/somepath/whatever", 404, "Not Found"); }
@Override public void start(Future<Void> future) throws Exception { super.start(); final Router router = Router.router(vertx); // body handler router.route().handler(BodyHandler.create()); // api route handler router.post(API_ADD).handler(this::apiAddUser); router.get(API_RETRIEVE).handler(this::apiRetrieveUser); router.get(API_RETRIEVE_ALL).handler(this::apiRetrieveAll); router.patch(API_UPDATE).handler(this::apiUpdateUser); router.delete(API_DELETE).handler(this::apiDeleteUser); String host = config().getString("user.account.http.address", "0.0.0.0"); int port = config().getInteger("user.account.http.port", 8081); // create HTTP server and publish REST service createHttpServer(router, host, port) .compose(serverCreated -> publishHttpEndpoint(SERVICE_NAME, host, port)) .setHandler(future.completer()); }