mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-06-24 13:45:11 +00:00
Stop fudging the server-side handling instructions for "add spot" into the spot data structure itself, instead break them out into a new area. This is a breaking change to the API so all API endpoints have been bumped to v2.
This commit is contained in:
31
server/handlers/api/v1_compatability.py
Normal file
31
server/handlers/api/v1_compatability.py
Normal file
@@ -0,0 +1,31 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user