Use url_for to generate api call urls in javascript (#27)

Without using url_for the middleware isn't taken into account, resulting
in the wrong url and the api call failing.