3 ms·
Hmm, a lot of my endpoints (in Spark) tend to look like public SomeService() { Spark.post("some/endpoint", this::someEndpoint, gson::toJson)
by marginalia_nu 3y ago
Hmm, a lot of my endpoints (in Spark) tend to look like
public SomeService() {
Spark.post("some/endpoint", this::someEndpoint, gson::toJson);
Spark.get("another/endpoint/:id". this::anotherEndpoint, gson::toJson);
//...
}
private ResponseType someEndpoint(Request request, Response response) {
Something some = gson.fromJson(request.body(), Something.class);
return new ResponseType(some.a, logic(some));
}
private ResponseType2 anotherEndpoint(Request request, Response response) {
return new ResponseType2(otherLogic(request.param("id"));
}
Like yeah I guess it could be have more well integrated json support, but it's not like this is heavy in boilerplate, and I do think it balances the need to occasionally access more low-level aspects of the HTTP stack well.
Not to detract from your project, of course.