diff --git a/CONTRIBUTORS b/CONTRIBUTORS --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2,5 +2,6 @@ Ishan Bhanuka Kalpit Kothari Katrin Leinweber +Krithik Vaidya Shankhadeep Dey Siddharth Ravikumar diff --git a/swh/web/api/urls.py b/swh/web/api/urls.py --- a/swh/web/api/urls.py +++ b/swh/web/api/urls.py @@ -1,4 +1,4 @@ -# Copyright (C) 2017-2018 The Software Heritage developers +# Copyright (C) 2017-2020 The Software Heritage developers # See the AUTHORS file at the top-level directory of this distribution # License: GNU Affero General Public License version 3, or any later version # See top-level LICENSE file for more information @@ -13,6 +13,7 @@ import swh.web.api.views.snapshot # noqa import swh.web.api.views.stat # noqa import swh.web.api.views.vault # noqa +import swh.web.api.views.ping # noqa from swh.web.api.apiurls import APIUrls diff --git a/swh/web/api/views/ping.py b/swh/web/api/views/ping.py new file mode 100644 --- /dev/null +++ b/swh/web/api/views/ping.py @@ -0,0 +1,21 @@ +# Copyright (C) 2020 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU Affero General Public License version 3, or any later version +# See top-level LICENSE file for more information + +from swh.web.api.apidoc import api_doc +from swh.web.api.apiurls import api_route + + +@api_route(r'/ping/', 'api-1-ping') +@api_doc('/ping/', noargs=True) +def ping(request): + """ + .. http:get:: /api/1/ping/ + + A simple endpoint used to check if the API is working. + + :statuscode 200: no error + + """ + return 'pong' diff --git a/swh/web/tests/api/views/test_ping.py b/swh/web/tests/api/views/test_ping.py new file mode 100644 --- /dev/null +++ b/swh/web/tests/api/views/test_ping.py @@ -0,0 +1,16 @@ +# Copyright (C) 2020 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU Affero General Public License version 3, or any later version +# See top-level LICENSE file for more information + +from swh.web.common.utils import reverse + + +def test_api_1_ping(api_client): + url = reverse('api-1-ping') + + rv = api_client.get(url) + + assert rv.status_code == 200, rv.data + assert rv['Content-Type'] == 'application/json' + assert rv.data == 'pong'