33from .boundmethod import BoundMethod
44from .method import Method
55from .parse_func import DEFAULT_BODY_PARAM , UrlTemplate , parse_func
6+ from .response_type import ResponseTypeLiteral , ResponseType
67
78_Func = TypeVar ("_Func" , bound = Callable [..., Any ])
89
@@ -15,9 +16,17 @@ def rest(
1516 additional_params : Optional [Dict [str , Any ]] = None ,
1617 method_class : Optional [Callable [..., BoundMethod ]] = None ,
1718 send_json : bool = True ,
19+ response_type : Optional [ResponseTypeLiteral ] = "json" ,
1820) -> Callable [[Callable ], Method ]:
1921 if additional_params is None :
2022 additional_params = {}
23+ try :
24+ response_type_enum = ResponseType (response_type )
25+ except ValueError :
26+ raise TypeError (
27+ f"'{ response_type } ' is not a valid response type. "
28+ f"Use one of { list (ResponseTypeLiteral .__args__ )} "
29+ )
2130
2231 def dec (func : Callable ) -> Method :
2332 method_spec = parse_func (
@@ -28,7 +37,7 @@ def dec(func: Callable) -> Method:
2837 additional_params = additional_params ,
2938 is_json_request = send_json ,
3039 )
31- return Method (method_spec , method_class = method_class )
40+ return Method (method_spec , method_class = method_class , response_type = response_type_enum )
3241
3342 return dec
3443
0 commit comments