News for hackers. Stuff that matters.
Re:Show HN: Java REST without annotations, DI nor reactive s... by Phelinofist on Sunday June 11, 2023 @03:39PM (#36284845)
Looks a bit like Spark - https://github.com/perwendel/spark
Re:Show HN: Java REST without annotations, DI nor reactive s... by moring on Sunday June 11, 2023 @03:52PM (#36284955)
I don't know why this was downvoted. Spark was actually one of the alternatives I considered before I concluded that I couldn't find any framework that suits me, and started writing grumpyrest.

The main issue I had with spark was, from what I could see, the lack of good JSON support. A major part of grumpyrest is its JSON serialization/deserialization framework (it's roughly half of the whole codebase!) which applies the same principles as grumpyrest does for REST, to JSON. (I even called it grumpyjson in anticipation that I might one day break this out as a standalone project).

Now don't get me wrong, I consider Jackson a high-quality framework, and I like very much how its author takes care of even the smallest details. It's not at all like Spring. However, in making it work as I wanted there were too many things that I could not solve to my satisfaction -- I could not abstract them in a way that was truly re-usable, and every API method would have to deal with these things again. This was even more true for Gson. So in the end, I used them (Gson, to be precise) as a low-level JSON library that basically translates between a JSON AST and serialized JSON, and did the high-level mapping to application classes myself.

Re:Show HN: Java REST without annotations, DI nor reactive s... by marginalia_nu on Sunday June 11, 2023 @04:37PM (#36285396)
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.

Re:Show HN: Java REST without annotations, DI nor reactive s... by winrid on Monday June 12, 2023 @01:13PM (#36297117)
Weird, usually gson is super straightforward for me. I don't think you should be working with the JSON AST. Rather, have a class that maps to the JSON, which is a DTO, and then translate that to your app layer.
Re:Show HN: Java REST without annotations, DI nor reactive s... by kasthack on Sunday June 11, 2023 @05:41PM (#36286015)