cowbird.api.requests ==================== .. py:module:: cowbird.api.requests Attributes ---------- .. autoapisummary:: cowbird.api.requests.LOGGER Functions --------- .. autoapisummary:: cowbird.api.requests.check_value cowbird.api.requests.get_request_method_content cowbird.api.requests.get_multiformat_body_raw cowbird.api.requests.get_multiformat_body cowbird.api.requests.get_path_param cowbird.api.requests.get_query_param Module Contents --------------- .. py:data:: LOGGER .. py:function:: check_value(value: Any, param_name: str, check_type: Union[Type[Any], Tuple[Type[Any], Ellipsis]] = str, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None) -> None Validates the value against specified type and pattern. :param value: value to validate. :param check_type: verify that parameter value is of specified type. Set to ``None`` to disable check. :param pattern: regex pattern to validate the input with. If value evaluates to ``False``, skip this kind of validation (default: :py:data:`ax.PARAM_REGEX`). :param param_name: path variable key. :param http_error: derived exception to raise on check failure (default: :class:`HTTPUnprocessableEntity`) :param msg_on_fail: message details to return in HTTP exception if check failed (default: description message of :class:`UnprocessableEntityResponseSchema`). :returns: None. :raises HTTPError: if the key is not an applicable path variable for this request. .. py:function:: get_request_method_content(request: pyramid.request.Request) -> Dict[str, Any] .. py:function:: get_multiformat_body_raw(request: pyramid.request.Request, key: str, default: Optional[Any] = None) -> Any Obtains the value of :paramref:`key` element from the request body according to specified `Content-Type` header. .. seealso:: - :func:`get_multiformat_body` .. py:function:: get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[str] = str, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None) -> str get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[Optional[str]] = (str, type(None)), pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None) -> Optional[str] get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[int] = int, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None) -> int get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[float] = float, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None) -> float get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[bool] = bool, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None) -> bool get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[List[Any]] = list, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None) -> cowbird.typedefs.JSON get_multiformat_body(request: pyramid.request.Request, key: str, default: Any = None, check_type: Type[Dict[str, Any]] = dict, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None) -> cowbird.typedefs.JSON Obtains and validates the matched value under :paramref:`key` element from the request body. Parsing of the body is accomplished according to ``Content-Type`` header. :param request: request from which to retrieve the key. :param key: body key variable. :param default: value to return instead if not found. If this default is ``None``, it will raise. :param check_type: verify that parameter value is of specified type. Set to ``None`` to disable check. :param pattern: regex pattern to validate the input with. If value evaluates to ``False``, skip this kind of validation (default: :py:data:`cowbird.api.exception.PARAM_REGEX`). :param http_error: derived exception to raise on check failure (default: :class:`HTTPUnprocessableEntity`) :param msg_on_fail: message details to return in HTTP exception if check failed (default: description message of :class:`UnprocessableEntityResponseSchema`). :returns: matched path variable value. :raises HTTPBadRequest: if the key could not be retrieved from the request body and has no provided default value. :raises HTTPUnprocessableEntity: if the retrieved value from the key is invalid for this request. .. seealso:: - :func:`get_multiformat_body_raw` .. py:function:: get_path_param(request: pyramid.request.Request, key: str, check_type: Any = str, pattern: Optional[Union[str, bool]] = ax.PARAM_REGEX, http_error: Optional[Type[pyramid.httpexceptions.HTTPError]] = None, msg_on_fail: Optional[str] = None) -> str Obtains the matched value located at the expected position of the specified path variable. :param request: request from which to retrieve the key. :param key: path variable key. :param check_type: verify that parameter value is of specified type. Set to ``None`` to disable check. :param pattern: regex pattern to validate the input with. If value evaluates to ``False``, skip this kind of validation (default: :py:data:`ax.PARAM_REGEX`). :param http_error: derived exception to raise on check failure (default: :class:`HTTPUnprocessableEntity`) :param msg_on_fail: message details to return in HTTP exception if check failed (default: description message of :class:`UnprocessableEntityResponseSchema`). :returns: matched path variable value. :raises HTTPError: if the key is not an applicable path variable for this request. .. py:function:: get_query_param(request: pyramid.request.Request, case_insensitive_key: Union[str, Iterable[str]], default: Optional[Any] = None) -> Any Retrieves a query string value by name (case-insensitive), or returns the default if not present.