Skip to content

Commit 3dba676

Browse files
author
s.astanin
committed
version 0.1.2 of the web API
* added an optional parameter "output", accepted values: "json"(default)|"png" If output=png is specified, the service will redirect directly to the plot image. This is an easy way to use gpxplot almost anywere. You can embed profile plots as ordinary images into any web page. For example: <img src="http://gpxplot.appspot.com/api/0.1.2/plot?gpxurl=URL_OF_YOUR_GPX_FILE&output=png" alt="Elevation profile" width="600" height="400">
1 parent fa5801b commit 3dba676

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

online/index.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,23 @@ def get(self):
7373
def post(self):
7474
try:
7575
url=plot_on_request(self.request)
76-
self.response.headers['Content-Type']='application/json'
77-
self.response.out.write(json.dumps({'url':url}))
76+
format=self.request.get("output","json")
77+
if format == "json":
78+
self.response.headers['Content-Type']='application/json'
79+
self.response.out.write(json.dumps({'url':url}))
80+
elif format == "png":
81+
self.redirect(url)
82+
else:
83+
raise Exception("Output format not supported.")
7884
except Exception, e:
7985
self.response.set_status(400,message='Exception: '+unicode(e))
8086

8187
application = webapp.WSGIApplication(
8288
[('/', MainPage),
8389
(r'/api/0.1/plot',ApiHandler),
84-
(r'/api/0.1.1/plot',ApiHandler)],
85-
debug=True)
90+
(r'/api/0.1.1/plot',ApiHandler),
91+
(r'/api/0.1.2/plot',ApiHandler),
92+
], debug=True)
8693

8794
def main():
8895
run_wsgi_app(application)

0 commit comments

Comments
 (0)