Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the request parameters using get in Spark Java framework?

Tags:

I'm new to sparkjava. I want to read my request params using spark java but I'm not able to find the correct syntax. please help me out. Below is my route method and the client call to it:

my client request url: /smartapp/getDataViewModelConfig?collId=123'

Route Method:

get("smartapp/getDataViewModelConfig/:id", "application/json", (request, response)          -> {   String id = request.params(":id"); } 

The 'id' field is returning null here. Any suggestions as to what went wrong here?

like image 442
anup kumar agarwal Avatar asked Mar 18 '15 16:03

anup kumar agarwal


People also ask

CAN GET method have query parameters?

When the GET request method is used, if a client uses the HTTP protocol on a web server to request a certain resource, the client sends the server certain GET parameters through the requested URL. These parameters are pairs of names and their corresponding values, so-called name-value pairs.

How do you request parameters?

Just go to your browser and search in Google 'javatpoint'. See the above image and URL; multiple parameters are sent in the URL. In the above URL, '&' should be followed by a parameter such as &ie=UTF-8. In this parameter, i.e., is the key and, UTF-8 is the key-value.

Why use Spark Java?

Spark provides 100x faster processing speeds for applications because it stores the intermediate processing data in memory and does not have any read and write to disk unless you ask it to do. In the case, you asked it to use disk it acts 10x faster than regular technologies like Hadoop.


1 Answers

If you have to work with an URL like /smartapp/getDataViewModelConfig?collId=123 you have to deal with query parameters in your implementation, like the following:

get("smartapp/getDataViewModelConfig", "application/json", (request, response)->{   String id = request.queryParams("collId");   return "HI " + id; } 
like image 135
Laercio Metzner Avatar answered Sep 17 '22 13:09

Laercio Metzner