4 ms·
TL;DR This is a bad example as we're mixing content construction with http service layer concepts. It should probably be more like: public class GreetingRe
by iovrthoughtthis 3y ago
TL;DR This is a bad example as we're mixing content construction with http service layer concepts. It should probably be more like:
public class GreetingResource {
@POST
@Path("/make-greeting")
public MakeGreetingResponse greet(final MakeGreetingRequest request) {
return MakeGreetingResponse(Greeting(request.name, request.addendum));
}
public Greeting(string name, Value addendum) {
if (addendum.isPresent()) {
return "Hello, " + request.name + "! " + addendum.getValue();
} else {
return "Hello, " + request.name + "!";
}
}
}
I think this is actually a little problematic. This handler is a likely location to mix http service logic with application logic and the interface exposed, via automatic parameter injection etc, implies the code in here should be application level but it's actually in the seam between then application and the http service layer.
Testing custom http service logic should involve mocking as it depends on objects and behaviours owned by the http service layer.
Code that we want to easily test for application level logic can be extracted into application level concepts.