Skip to content

skip empty fields in response #518

@emiltin

Description

@emiltin

this request:

http://routes.ibikecph.dk/viaroute?jsonp=jQuery18205384856714844667_1354023211018&z=13&output=json&geomformat=cmp&checksum=849255673&loc=55.691810,12.532139&loc=55.680391,12.579517&hint=s2cAAL0AAAByAAAA____f96UWSLGm98_RPZUAMUxEwB&instructions=false&alt=false

produces this reponse:

{"version": 0.3,"status":0,"status_message": "Found route between points","route_geometry": "ih|rIgvnkAZyAWWg@c@QQ^qB@qBd@iCpCoA_@iD?sA|@aBd@cAsCoGz@kAhAeClFqKdA}CpA{FJ_@v@sC|BqIyBqCoA_Bj@sB~@mDNk@\\uA~AgG\\eAe@uCqBw@n@yGy@s@tAkFgCwC|@eDp@aCBuGvBuJd@sBgDsDb@_BFYlBsGNk@BM\i@Tk@t@oD`B{F}BuCXkB{BbAwFfAsGhAaHBOReBfAxAvAeEIOxAwHr@_Dv@iDn@}B|@}Cp@sBlBtCNJrAoFl@bD","route_instructions": [],"route_summary":{"total_distance":4157,"total_time":857,"start_point":"service","end_point":"Kronprinsensgade"},"alternative_geometries": [],"alternative_instructions":[],"alternative_summaries":[],"route_name":["",""],"alternative_names":[["",""]],"via_points":[[55.69173,12.53236 ],[55.68068,12.57925 ]],"hint_data": {"checksum":849255673, "locations": ["O596ALIAAAAAAAAASQAAAAAAAAAAAAAAlfpUAHQfEwC", "s2cAAL0AAAByAAAA____f96UWSLGm98_RPZUAMUxEwB"]},"transactionId": "OSRM Routing Engine JSON Descriptor (v0.3)"}

since we requested instructions=false, i would suggest leaving out:

"route_instructions": []

since we requested alt=false, i would also suggest leaving out these empty field:

"alternative_geometries": []
"alternative_instructions":[]
"alternative_summaries":[]
"alternative_names":[["",""]]

in fact, why not generally leave out empty fields whenever possible. i don't think it would complicate parsing at the front-end. in fact it would simplify things and make them easier to understand.

in cases where no route is found, you get something like this:

{"version": 0.3,"status":207,"status_message": "Cannot find route between points","route_geometry": "","route_instructions": [],"route_summary":{"total_distance":0,"total_time":214748365,"start_point":"","end_point":""},"alternative_geometries": [],"alternative_instructions":[],"alternative_summaries":[],"route_name":["",""],"alternative_names":[["",""]],"via_points":[],"hint_data": {"checksum":849255673, "locations": ["88YAAIoEAACnAAAA____f2qAukMU3do_sf1UAK8xEwD", "__________8AAAAA____fwAAAAAAAAAAwKt2_wAAAIB"]},"transactionId": "OSRM Routing Engine JSON Descriptor (v0.3)"}

which contains a lot of nothing, and could be simplified to:

{"version": 0.3,"status":207,"status_message": "Cannot find route between points",,"hint_data": {"checksum":849255673, "locations": ["88YAAIoEAACnAAAA____f2qAukMU3do_sf1UAK8xEwD", "__________8AAAAA____fwAAAAAAAAAAwKt2_wAAAIB"]},"transactionId": "OSRM Routing Engine JSON Descriptor (v0.3)"}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions