diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 34189ee1..d1339315 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1,6 +1,7 @@ Daniele Serafini 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 index 3c5ccf02..0659ba36 100644 --- a/swh/web/api/urls.py +++ b/swh/web/api/urls.py @@ -1,19 +1,20 @@ -# 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 import swh.web.api.views.content # noqa import swh.web.api.views.directory # noqa import swh.web.api.views.identifiers # noqa import swh.web.api.views.origin # noqa import swh.web.api.views.origin_save # noqa import swh.web.api.views.release # noqa import swh.web.api.views.revision # noqa 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 urlpatterns = APIUrls.get_url_patterns() diff --git a/swh/web/api/views/ping.py b/swh/web/api/views/ping.py new file mode 100644 index 00000000..9a2a722b --- /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 index 00000000..80659db4 --- /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'