response_helpers.core module¶
Response Helpers for FastAPI¶
- response_helpers.core.canonicalize_tz(tstring: str) str ¶
Browsers are not consistent with how they format times with timezones for example Safari: Tue Sep 08 2020 21:13:00 GMT-0500 (CDT) Chrome: Tue Sep 08 2020 21:13:00 GMT-0500 (Central Daylight Time) This function tries to coerce the time string into the Safari format as it is more compatible with other time/date functions
- response_helpers.core.get_webpack_static_imports(course)¶
- response_helpers.core.http_422error_detail(loc: List[str], msg: str, err_type: str) List[dict] ¶
The 422 indicates that the request was not formatted correctly. This function provides the details on what was missing. Based on information we get from Pydantic.
- Parameters:
loc (List[str]) – the location of the error in the request
msg (str) – A descriptive message about the error.
err_type (str) – the specific error that was raised. e.g. value_error, type_error, integrity_error.
- Returns:
A list of dictionaries that can be used to construct the detail for the response.
- Return type:
List[dict]
- response_helpers.core.make_json_response(status: int = 200, detail: Optional[Any] = None) JSONResponse ¶
Format a proper JSON response for the API.
- Parameters:
status (int, optional) – status code of the response, defaults to status.HTTP_200_OK
detail (Any, optional) – detailed values for the response. Note that the contents of the detail are api independent, but the goal is for all API calls to use this format., defaults to None
- Returns:
Return the JSON response object that FastAPI expects.
- Return type:
JSONResponse