Skip to content

Commit

Permalink
Pass a parameter called 'json' instead of 'format'.
Browse files Browse the repository at this point in the history
This follows @codingjoe's suggested approach, which I diverged from earlier.
  • Loading branch information
ashokdelphia committed Apr 23, 2019
1 parent 8961aab commit a964002
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Getting machine readable JSON reports

If you want machine readable status reports you can request the ``/ht/``
endpoint with the ``Accept`` HTTP header set to ``application/json``
or pass ``format=json`` as a query parameter.
or pass ``json=1`` as a query parameter.

The backend will return a JSON response:

Expand All @@ -166,9 +166,9 @@ The backend will return a JSON response:
"S3BotoStorageHealthCheck": "working"
}
$ curl -v -X GET http://www.example.com/ht/?format=json
$ curl -v -X GET http://www.example.com/ht/?json=1
> GET /ht/?format=json HTTP/1.1
> GET /ht/?json=1 HTTP/1.1
> Host: www.example.com
>
< HTTP/1.1 200 OK
Expand Down
2 changes: 1 addition & 1 deletion health_check/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def _run(plugin):
accept_format = request.META.get('HTTP_ACCEPT', '')
accepts_json = 'application/json' in accept_format

if accepts_json or request.GET.get('format') == 'json':
if accepts_json or request.GET.get('json', False):
return self.render_to_response_json(plugins, status_code)
else:
context = {'plugins': plugins, 'status_code': status_code}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def run_check(self):

plugin_dir.reset()
plugin_dir.register(JSONSuccessBackend)
response = client.get(self.url, {'format': 'json'})
response = client.get(self.url, {'json': 1})
assert response.status_code == 200, response.content.decode('utf-8')
assert response['content-type'] == 'application/json'
assert json.loads(response.content.decode('utf-8')) == \
Expand All @@ -108,7 +108,7 @@ def run_check(self):

plugin_dir.reset()
plugin_dir.register(JSONErrorBackend)
response = client.get(self.url, {'format': 'json'})
response = client.get(self.url, {'json': 1})
assert response.status_code == 500, response.content.decode('utf-8')
assert response['content-type'] == 'application/json'
assert 'JSON Error' in json.loads(response.content.decode('utf-8'))[JSONErrorBackend().identifier()]

0 comments on commit a964002

Please sign in to comment.