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?
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.
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.
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.
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; }
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