import json import tornado from core.utils import serialize_everything class V1GoneHandler(tornado.web.RequestHandler): """Returns 410 Gone with a message for any endpoints in the old API that have breaking changes in the new one or have been retired.""" def post(self): self.set_status(410) self.write(json.dumps( "This API endpoint has a breaking change or has been removed in the current version of the Spothole API. Please see /apidocs for details of the current API version and the endpoints available.", default=serialize_everything )) self.set_header("Cache-Control", "no-store") self.set_header("Content-Type", "application/json") class V1RedirectHandler(tornado.web.RequestHandler): """Returns 308 Permanent Redirect from any path in the old API to the new one, where there were no breaking changes.""" def get(self, path): new_url = "/api/v2/" + path if self.request.query: new_url += "?" + self.request.query self.set_status(308) self.set_header("Location", new_url) self.finish()