I wanted to check if we can use getparam to parse start_time and end_time from the below request URL
https://[--hostname--]/sample_app/apthroughput/getAllControllers?start_time=<start time value>&end_time=<end time value>&label=<selected label>
The parsing of a query string is quite straightforward except for when there are multiple values for the same query param.
e.g.: https://[--hostname--]/sample_app/apthroughput/getAllControllers?type=xxx&type=yyy
in such cases the code below helps getting all the params of a kind in List<String>
This answer gives an idea. Copying from it:
HttpServerRequest request = RoutingContext.request();
MultiMap params = request.params();
List<String> param = params.getAll("personId");
Here you can get list of personId. URI be like
localhost:8081/myApi?personId=1&personId=2&personId=3
Here's an example:
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
HttpServer server = vertx.createHttpServer();
server.requestHandler(request -> {
String startTime = request.getParam("start_time");
String endTime = request.getParam("end_time");
// This handler gets called for each request that arrives on the server
HttpServerResponse response = request.response();
response.putHeader("content-type", "text/plain");
// Write to the response and end it
response.end(String.format("Got start time %s, end time %s", startTime, endTime));
});
server.listen(8888);
}
Open http://localhost:8888/?start_time=20161014&end_time=20161015 to see the results.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With