Is it possible to set up a Tornado server to run on a certain port, actively serving an API at several URLs, and having it return an HTTP 400: Bad request
on every other URL requested on that port?
Say for example that I've got a simple GET and POST API running on http://example.com:1234/get
and http://example.com:1234/post
respectively that return 2xx
statuses as appropriate, but requests to http://example.com:1234/someRandomUrlRequest
return an HTTP 400
.
Put a catch-all URL route at the end of your application's list of routes. Make a handler for that catch-all route that raises HTTPError(400) for GET and POST requests. Here's an example:
Testing this with curl: