Description
Is your feature request related to a problem? Please describe.
Automatically generating models is great for many of our simple cases. However, there are a few cases where we'd like access to the original HTTP response - particularly the headers - without having to augment with another library like requests
.
One example is when paginating results. We want to retrieve a list of models, but there's also a HTTP header like X-Result-Count
that tells us how many total results are available.
Describe the solution you'd like
It would be great to have a Response
wrapper object that would minimally preserve the HTTP headers and still return the deserialized models.
Sample might look like:
T = TypeVar("T")
class Response(Generic[T]):
def body() -> T:
pass
def headers() -> Dict[str, List[str]]:
pass
For compatibility reasons this could be an option like --wrap-responses
which is False
by default, but when True
would update all the method signatures to use something like Response[Model]
or Response[List[Model]]
, etc.
Coming from the Java world, I've seen and used something like this in the past: https://square.github.io/retrofit/2.x/retrofit/retrofit2/Response.html
Describe alternatives you've considered
The current alternatives are either lose/ignore the functionality afforded from the headers or to manually make calls via another library (like requests
) and manually parse the response ourselves.