-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#241: Add non-backend specific infrastructure for /ping
- Loading branch information
1 parent
0c57614
commit 1cf4972
Showing
4 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
datagateway_api/src/resources/non_entities/ping_endpoint.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from flask_restful import Resource | ||
|
||
|
||
def ping_endpoint(backend, **kwargs): | ||
""" | ||
Generate a flask_restful Resource class using the configured backend. In main.py | ||
these generated classes are registered with the api e.g. | ||
`api.add_resource(get_endpoint("Datafiles", DATAFILE), "/datafiles")` | ||
:param backend: The backend instance used for processing requests | ||
:type backend: :class:`DatabaseBackend` or :class:`PythonICATBackend` | ||
:return: The generated ping endpoint class | ||
""" | ||
|
||
class Ping(Resource): | ||
def get(self): | ||
""" | ||
Pings the connection method to ensure the API is responsive | ||
:return: String: A standard OK message, 200 | ||
--- | ||
summary: Ping API connection method | ||
description: Pings the API's connection method to check responsiveness | ||
tags: | ||
- Ping | ||
responses: | ||
200: | ||
description: Success - the API is responsive on the backend configured | ||
content: | ||
application/json: | ||
schema: | ||
type: string | ||
description: OK message | ||
example: DataGateway API OK | ||
500: | ||
description: Pinging the API's connection method has gone wrong | ||
""" | ||
return backend.ping(**kwargs), 200 | ||
|
||
return Ping |