Skip to content

Commit

Permalink
feat: add heartbeat to authoring api (#34449)
Browse files Browse the repository at this point in the history
* feat: add heartbeat to authoring api
  • Loading branch information
connorhaugh authored Apr 10, 2024
1 parent eb26333 commit df3c38c
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v0/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
TranscriptView,
YoutubeTranscriptCheckView,
YoutubeTranscriptUploadView,
APIHeartBeatView
)
from .views import assets
from .views import authoring_videos
Expand Down Expand Up @@ -45,6 +46,9 @@
),

# Authoring API
re_path(
r'^heartbeat$', APIHeartBeatView.as_view(), name='heartbeat'
),
re_path(
fr'^file_assets/{settings.COURSE_ID_PATTERN}$',
assets.AssetsCreateRetrieveView.as_view(), name='cms_api_create_retrieve_assets'
Expand Down
1 change: 1 addition & 0 deletions cms/djangoapps/contentstore/rest_api/v0/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .advanced_settings import AdvancedCourseSettingsView
from .tabs import CourseTabSettingsView, CourseTabListView, CourseTabReorderView
from .transcripts import TranscriptView, YoutubeTranscriptCheckView, YoutubeTranscriptUploadView
from .api_heartbeat import APIHeartBeatView
48 changes: 48 additions & 0 deletions cms/djangoapps/contentstore/rest_api/v0/views/api_heartbeat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
""" View For Getting the Status of The Authoring API """
import edx_api_doc_tools as apidocs
from rest_framework.views import APIView
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework import status
from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin, view_auth_classes
import cms.djangoapps.contentstore.toggles as toggles


class APIHeartBeatView(DeveloperErrorViewMixin, APIView):
"""
View for getting the Authoring API's status
"""

@apidocs.schema(
parameters=[],
responses={
200: "The API is online",
401: "The requester is not authenticated.",
403: "The API is not availible",
},
)
@view_auth_classes(is_authenticated=True)
def get(self, request: Request):
"""
Get an object containing the Authoring API's status
**Example Request**
GET /api/contentstore/v0/heartbeat
**Response Values**
If the request is successful, an HTTP 200 "OK" response is returned.
The HTTP 200 response contains a single dict with the "authoring_api_enabled" value "True".
**Example Response**
```json
{
"authoring_api_enabled": "True"
}
```
"""
if toggles.use_studio_content_api():
return Response({'status': 'heartbeat successful'}, status=status.HTTP_200_OK)
return Response(status=status.HTTP_403_FORBIDDEN)

0 comments on commit df3c38c

Please sign in to comment.