Add ping endpoing

This commit is contained in:
Matthias 2019-11-11 20:09:58 +01:00
parent 904ae5af91
commit 75d5ff69ef
3 changed files with 21 additions and 1 deletions

View File

@ -22,7 +22,14 @@ Sample configuration:
!!! Danger "Password selection"
Please make sure to select a very strong, unique password to protect your bot from unauthorized access.
You can then access the API by going to `http://127.0.0.1:8080/api/v1/version` to check if the API is running correctly.
You can then access the API by going to `http://127.0.0.1:8080/api/v1/ping` to check if the API is running correctly.
This should return the response:
``` output
{"status":"pong"}
```
All other endpoints will require authentication, so are not available through a webrowser.
To generate a secure password, either use a password manager, or use the below code snipped.

View File

@ -169,6 +169,8 @@ class ApiServer(RPC):
view_func=self._status, methods=['GET'])
self.app.add_url_rule(f'{BASE_URI}/version', 'version',
view_func=self._version, methods=['GET'])
self.app.add_url_rule(f'{BASE_URI}/ping', 'ping',
view_func=self._ping, methods=['GET'])
# Combined actions and infos
self.app.add_url_rule(f'{BASE_URI}/blacklist', 'blacklist', view_func=self._blacklist,
@ -224,6 +226,13 @@ class ApiServer(RPC):
msg = self._rpc_stopbuy()
return self.rest_dump(msg)
@rpc_catch_errors
def _ping(self):
"""
simple poing version
"""
return self.rest_dump({"status": "pong"})
@require_login
@rpc_catch_errors
def _version(self):

View File

@ -64,6 +64,10 @@ def test_api_not_found(botclient):
def test_api_unauthorized(botclient):
ftbot, client = botclient
rc = client.get(f"{BASE_URI}/ping")
assert_response(rc)
assert rc.json == {'status': 'pong'}
# Don't send user/pass information
rc = client.get(f"{BASE_URI}/version")
assert_response(rc, 401)