4 ms·
Can't fathom why annotation are used for this, except maybe as a holdover from years ago when Java didn't have certain language features. Other approaches in J
by topspin 4y ago
Can't fathom why annotation are used for this, except maybe as a holdover from years ago when Java didn't have certain language features. Other approaches in Java are much nicer and involve zero annotations. Example (from the Spark Java microframework documentation):
path("/api", () -> {
before("/*", (q, a) -> log.info("Received api call"));
path("/email", () -> {
post("/add", EmailApi.addEmail);
put("/change", EmailApi.changeEmail);
delete("/remove", EmailApi.deleteEmail);
});
path("/username", () -> {
post("/add", UserApi.addUsername);
put("/change", UserApi.changeUsername);
delete("/remove", UserApi.deleteUsername);
});
});
All your endpoints concisely and composibly mapped out in code, and not smeared across dozens or hundreds of methods and classes. Not an annotation in sight; just plain old Java.
- seanalltogether 4y agoThe code I posted above is used for client side apps, not server side. Client code typically has to accommodate calling different systems that use different patterns so having more flexibility in mapping endpoints to results is more important.
- syspec 4y agoThat looks worse. Shorter code is not always better code