I was wondering if you can help me out with a problem I have when using spark get the route. I am working with these two endpoints:
/get?contains=sometext.
/get?_id=abc.
I have these two get routes set to retrieve the jQuery params for each endpoint.
get("/get","application/json",(request, response) -> {
String id = request.queryParams("_id");
return "Hello get _id : " + id;
});
Second:
get("/get","application/json",(request, response) -> {
String contains = request.queryParams("contains");
return "Hello get contains : " + contains;
});
from these two get routes only the contains queryParams work fine but the _id get route doesn't work because it returns null
. I wonder if it has to do with the fact that both endpoints have the same get path.
Any help will be very appreciated. thanks
In Sparkjava you should have only one endpoint per route (otherwise, I'd guess it will consider only the last endpoint that you defined).
Then, you could have the logic that checks what are the passed parameters inside it using:
request.queryParams("contains")
request.queryParams("_id")
or just
request.queryParams()
to get all of them as a list and then check this list for these params.
If one of these is null
it means that this param wasn't passed.