By checking for a URL argument in the request.args dictionary, and then checking if the argument evaluates as true, we can determine if all of the state geometries should be returned. The GeoJSON response is generated from the state's geometry by using the to_shape function and the shapely.geometry.geo.mapping (shortened to smapping) function:
@app.route('/nba/api/v0.1/state', methods=['GET'])def get_states(): smapping = shapely.geometry.geo.mapping states = session.query(State).all() data = [{"type": "Feature", "properties":{"state":state.name,"id":state.id}, "geometry":{"type":"MultiPolygon", "coordinates":"[Truncated]"}, } for state in states] if "geometry" in request.args.keys(): if request.args["geometry"]=='1' ...