In case of I'm having this code:
class MyApp():
def __init__(self):
self.bottle = Bottle()
self.bottle.route('/')(self.show_api)
self.bottle.route('/api/')(self.show_api)
self.bottle.route('/api/item', method='PUT')(self.save_item)
def show_api(self):
return <JSON representation of the API?>
Is it possible to get a REST API documentation in JSON format from that? fro some reason self.bottle.routes didn't return anything useful.
Thanks!
Bottle.route()
is meant to be used as a decorator:So it does return something useful: the decorated function.
You can then use
app.routes
to get a list of declared routes.Output:
A function is not directly JSON serializable. But you could easily use
str
to get a string represenation.Actually the right way to generate the JSON API description seems to be: