Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] Implement Endpoints for Status Page #952

Open
5 tasks
JoshuaOloton opened this issue Aug 24, 2024 · 0 comments
Open
5 tasks

[FEAT] Implement Endpoints for Status Page #952

JoshuaOloton opened this issue Aug 24, 2024 · 0 comments

Comments

@JoshuaOloton
Copy link
Contributor

JoshuaOloton commented Aug 24, 2024

Description

Develop API endpoints to retrieve and update the details of API status. The following endpoints should be created:

  1. Fetch API Status - Retrieve the details of the API status of all endpoints.
  2. Post API Status - Accept the results of automated tests and update the health status of each API group in the database.

Acceptance Criteria

Fetch API Status

  • The endpoint `/api/v1/api-status is accessible via a GET request.
  • If an unexpected server error occurs, the endpoint returns a 500 Internal Server Error status.
  • The response body of a 500 error response contains an error message indicating that an unexpected error occurred.

POST API Status

  • The endpoint /api/v1/api-status is accessible via a POST request.
  • The endpoint accepts a JSON payload containing API status data.
  • On successful creation or update of API status group, it returns a 201 Created status.
  • If the request is invalid (e.g., missing fields), it returns a 400 Bad Request status.
  • If an unexpected server error occurs, it returns a 500 Internal Server Error status.

Purpose

  • These endpoints provide a backend service that allows retrieving and updating the health status of APIs.

Requirements

  • Implement the endpoint to get the details of the entire API status.
  • Implement the endpoint to post API status updates.

Expected Outcome

  • API endpoints that securely retrieve and update API status details.

Tasks

  • Create an endpoint /api/v1/api-status to retrieve the API status details.
  • Create an endpoint /api/v1/api-status to accept updates for API statuses.
  • Write unit tests for both the fetch and post API status endpoints.

Database Schema

Table api_status {
  id int [pk, increment] // Primary key
  api_group varchar [not null]
  status varchar [not null] // Operational, Degraded, Down
  response_time decimal // Response time in milliseconds
  details text
  last_checked timestamp [default: `CURRENT_TIMESTAMP`]
  created_at timestamp [default: `CURRENT_TIMESTAMP`]
  updated_at timestamp
}

Endpoint URLs

Fetch API Status

  • GET /api/v1/api-status

Post API Status

  • POST /api/v1/api-status

Responses

Fetch API Status - Success Response

  • Code: 200 SUCCESS

  • Content:

{
    "status_code": 200,
    "success": true,
    "message": "All API Status fetched successfully",
    "data": [
        {
            "last_checked": "2024-08-23T23:21:32.555541+01:00",
            "id": "066c90b6-c907-7357-8000-3ae387f7153d",
            "created_at": "2024-08-23T23:21:32.555541+01:00",
            "status": "Down",
            "response_time": null,
            "api_group": "Login User",
            "details": "Bad Gateway",
            "updated_at": "2024-08-23T23:21:32.555541+01:00"
        },
        {
            "last_checked": "2024-08-23T23:21:32.572124+01:00",
            "id": "066c90b6-c927-7fb5-8000-36f31796d5c0",
            "created_at": "2024-08-23T23:21:32.572124+01:00",
            "status": "Down",
            "response_time": null,
            "api_group": "BE-PY-001-Fetch data privacy setting",
            "details": "Bad Gateway",
            "updated_at": "2024-08-23T23:21:32.572124+01:00"
        },
    ]
}

Post API Status - Success Response

  • Code: 201 CREATED

  • Content:

{
    "status_code": 201,
    "success": true,
    "message": "API Status created successfully",
    "data": {
        "last_checked": "2024-08-23T20:54:44.092052+01:00",
        "id": "066c8e35-2ac5-786b-8000-87167f0401ca",
        "created_at": "2024-08-23T20:30:26.672906+01:00",
        "response_time": null,
        "status": "Down",
        "api_group": "Blog API",
        "details": "API not responding (HTTP 503)",
        "updated_at": "2024-08-23T20:54:44.092052+01:00"
    }
}

Error Responses

  • Code: 422: UNPROCESSABLE CONTENT / VALIDATION ERROR

  • Content:

{
 "errors": {
   "field": "<field>",
   "message": "<message>"
 }
}
  • Code: 500 INTERNAL SERVER ERROR

  • Content:

{
 "error": "An unexpected error occurred"
}

Example Request

Fetch API Status

curl -X GET "https://<base-url>/api/v1/api-status" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer <your_jwt_token>"

Post API Status

curl -X POST "https://<base-url>/api/v1/api-status" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer <your_jwt_token>" \
     -d '{
         "api_group": "Authentication API",
         "status": "Operational",
         "response_time": 320,
         "details": "All tests passed"
     }'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant