I am working on Restful API, in memory we have a Json-format object, customer needs to download this json object with zip file format.
Now I am using Vertx to implement this GET response, the response needs to return a ZIP-format binary data, basically it looks like the following,
JsonObject jsonObject = new JsonObject();
jsonObject.put("a", "a1")
.put("b", "b1");
routingContext
.response()
.setStatusCode(200)
.putHeader("Content-Type", "application/zip")
.....
.....
I have no idea how to implement it with Vertx routingContext, could anybody give points or some example code in order to implement it?
I think the only item you are missing in the method chain is the last line:
.end(...);
This method is overloaded multiple times. For the case up here, the method would look like
.end(Json.encode(jsonObject));
withjsonObject
converted toString
. I assume this is only the example since this would return the zip file but one that cannot be opened with zip archive software (because it's a JSON obviously).end(...)
method also acceptsBuffer
from theio.vertx.core.buffer.Buffer
package, maybe that is what you are looking for - turning the data you have intoBuffer
and serving it.