Skip to content

Instantly share code, notes, and snippets.

@amcgregor
Last active July 15, 2019 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amcgregor/dd1ffffd29cde459a80f5e3bfade3d00 to your computer and use it in GitHub Desktop.
Save amcgregor/dd1ffffd29cde459a80f5e3bfade3d00 to your computer and use it in GitHub Desktop.
An impressive number of endpoint arguments, comparing Flask vs. WebCore for the same endpoint. Identifying "boilerplate" / "overhead" involved in typecasting and validation.
## Flask ("Regular Expression URL Routes")
@app.route('/gps/<float:lat>/<float:lon>/<int:time>/<float:altitude>/<float:speed>/<float:bearing>/<float:accuracy>')
def handler(lat, lon, time, altitude, speed, bearing, accuracy):
...
# It's so explicit, you have to define the entire arglist twice!
# It's very specific about int vs. float, not matching integer like numbers for floating point components at all.
# v.
## WebCore ("Object Dispatch" + Python 3 Function Annotations for typecasting)
def handler(lat:float, lon:float, time:int, altitude:float, speed:float, bearing:float, accuracy:float):
...
# This won't care about the distinction between being passed 27 or being passed 27.0.
# The result will always be a float.
# Additionally, endpoint arguments are sourced from multiple allowable locations, permitting:
# GET /?lat=&lon=&... - Query string arguments. (QSA/QSO)
# GET /lat/lon/time/alt/spd/bearing/accuracy - Unprocessed remianing path elements.
# POST / lat=&lon=&... - Form-encoded POST body.
# POST / {"lat": ..., "lon": ..., ...} - JSON-encoded POST body.
# Even permits mixed usage: (though this is generally not advised)
# POST /lat/lon time=…&alt=…&… - Path + QSO + form POST.
# POST /lat/lon/time?altitude=&speed= {"bearing": ..., "accuracy": ...} - Path + QSO + JSON body.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment