hngprojects / hng_boilerplate_python_fastapi_web

Apache License 2.0
154 stars 137 forks source link

[FEAT] Implement Endpoints for Status Page #952

Open JoshuaOloton opened 3 weeks ago

JoshuaOloton commented 3 weeks ago

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

POST API Status

Purpose

Requirements

Expected Outcome

Tasks

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

Post API Status

Responses

Fetch API Status - Success Response


### Post API Status - Success Response
 - #### Code: 201 CREATED
 - #### Content:
```json
{
    "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

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"
     }'