|
|
|
|
|
by joshuamorton
2722 days ago
|
|
> This is vanilla Java. No, its Java EE, which like I said, has an entire library devoted to safe marshalling[1]. Marshmallow does the same thing for you in python. Java EE including a marshalling library has nothing to do with static typing. This is python + flask + marshmallow (2 very common web libraries)+ a 2 line helper function: @dataclass
class Thing():
text: str
when: datetime.datetime
@app.route('/thing', methods=['POST'])
def handle():
thing = unmarshall(Thing, request.form)
# blah
Or, like I said, use protos, where this would be something like from thingproto import Thing, ThingService, ThingResponse
class ThingServiceHandler(ThingService):
def HandleThing(request: Thing, response: ThingResponse):
# blah
and everything is validated.[1]: https://dennis-xlc.gitbooks.io/restful-java-with-jax-rs-2-0-... |
|
Dragging protobufs into this is weird too; you've ignored the IDL and build infrastructure required to set that up, and in any case that's specific to when you're working with protobuf APIs.
I'll go back to my earlier point, which I think you've illustrated fairly well, which is that well-written Java code tends to be more concise and less verbose than Python (and friends). Our two examples are nearly identical in terms of meaningful lines of code, but in the Python example you have to ask for marshaling.
I'll also point out that flask (which I use myself for python webapps) handlers are forced to interact with flask-specific objects and therefore are obnoxious to test; the JAX-RS example is pure program logic and can be tested as vanilla Java code. This is one of the big advantages of moving marshaling "out" of your program code.