Java Spark how do I return an error message when parameters are missing from the URL?

103
May 08, 2019, at 12:30 PM

I'm currently creating a REST service using Java Spark. How would I go about returning an error message when parameters are missing from the URL? e.g. /stations?latitude=&longitude=&type= then an error would appear e.g. "Make sure you set the latitude, longitude and type parameters"

Currently, this is what I have started with:

    port(8080);

    get("/stations", new Route() {
        @Override
        public Object handle(Request request, Response response) throws Exception {
            String latitude = request.queryParams("latitude");
            String longitude = request.queryParams("longitude");
            String type = request.queryParams("type");
            return latitude + longitude + type;
        }
    });

}

}

READ ALSO
How to convert number to words in java

How to convert number to words in java

We currently have a crude mechanism to convert numbers to words (eg

203
Ball.setBounds dosen't work in the right way

Ball.setBounds dosen't work in the right way

I can't properly set Ball Bounds in JFrame

136
How do I resolve Unhandled Exception Error in Wildfly?

How do I resolve Unhandled Exception Error in Wildfly?

I've been tasked with finding a solution to a bug that we have been seeing for ~15 years off and on since Dec '17 but started happening WAY more in Dec '18

436
MongoDB with Java: Finding the document with max value

MongoDB with Java: Finding the document with max value

I have a rudimentary at best understanding of MongoDB and aggregationI have not been able to find a clear example of how one might compare multiple documents which match a criteria and return 1 document with the maximum value in a specific attribute

119