Skip to content

date/time stamps and reference requested in response #37

@eatyourpeas

Description

@eatyourpeas

Now that multiple references are offered, there is currently no information in the response object either that the request was made or the reference that the return data corresponds to. I would be ideal to put in the body of the response with all the results but this would represent a breaking change for users, so the other option is to put it in the response header. Users can discard this, but also they can use this if they need.

FastAPI has this feature to add custom headers:

from fastapi import FastAPI, HTTPException, Response
from typing import List
from datetime import datetime
import constants

app = FastAPI()

@uk_who.post(
    "/fictional-child-data", tags=["uk-who"], response_model=List[MeasurementObject]
)
def fictional_child_data(fictional_child_request: FictionalChildRequest, response: Response):
    """
    ## UK-WHO Fictional Child Data Endpoint

    * Generates synthetic data for demonstration or testing purposes
    """
    try:
        life_course_fictional_child_data = generate_fictional_child_data(
            measurement_method=fictional_child_request.measurement_method,
            sex=fictional_child_request.sex,
            start_chronological_age=fictional_child_request.start_chronological_age,
            end_age=fictional_child_request.end_age,
            gestation_weeks=fictional_child_request.gestation_weeks,
            gestation_days=fictional_child_request.gestation_days,
            measurement_interval_type=fictional_child_request.measurement_interval_type,
            measurement_interval_number=fictional_child_request.measurement_interval_number,
            start_sds=fictional_child_request.start_sds,
            drift=fictional_child_request.drift,
            drift_range=fictional_child_request.drift_range,
            noise=fictional_child_request.noise,
            noise_range=fictional_child_request.noise_range,
            reference=constants.UK_WHO,
        )
        
        # Set response headers
        response.headers["X-Date-Time"] = datetime.utcnow().isoformat()
        response.headers["X-Reference"] = constants.UK_WHO

        return life_course_fictional_child_data
    except Exception as e:
        raise HTTPException(
            status_code=422,
            detail=f"Not possible to create UK-WHO fictional child data. Error: {str(e)}",
        )

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions