2016-03-28 12:14:50 +00:00
|
|
|
''' Exports RequireJson. '''
|
|
|
|
|
2016-03-19 20:37:04 +00:00
|
|
|
import falcon
|
|
|
|
|
|
|
|
class RequireJson(object):
|
2016-03-28 12:14:50 +00:00
|
|
|
''' Sanitizes requests so that only JSON is accepted. '''
|
|
|
|
|
2016-03-19 20:37:04 +00:00
|
|
|
def process_request(self, req, resp):
|
2016-03-28 12:14:50 +00:00
|
|
|
''' Executed before passing the request to the API. '''
|
2016-03-19 20:37:04 +00:00
|
|
|
if not req.client_accepts_json:
|
|
|
|
raise falcon.HTTPNotAcceptable(
|
|
|
|
'This API only supports responses encoded as JSON.')
|