You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to be able to use a middleware on the rest client that uses a Pydantic model on the response.
This has some similarity to using hooks, bit hooks currently don't allow changing the return value, they are only evaluated alongside.
Possibly this can be done via the low-level access to request's Session added in #1844 and mounting a connection adapter, however it doesn't necessarily need to be that low-level, and the involvement is quite substantial.
Feature description
I would like to be able to use a middleware on the rest client that uses a Pydantic model on the response.
This has some similarity to using
hooks
, bit hooks currently don't allow changing the return value, they are only evaluated alongside.Currently, I am doing something like this:
for pagination it is a bit more tricky even, as the value returned from
.paginate
is only thedata
part of the response, e.g. for something like:only
List[Company]
is returned from.paginate
, as the pagination property is evaluated and used internally.In my ideal world I'd be able to do something like this:
or even better:
Other rest clients have this notion - for example Axios interceptors.
Possibly this can be done via the low-level access to
request
'sSession
added in #1844 and mounting a connection adapter, however it doesn't necessarily need to be that low-level, and the involvement is quite substantial.My current workaround
AuthenticationErrors | NotFoundErrors | AuthorizationErrors | ValidationErrors
are pydantic models looking roughly like this:Are you a dlt user?
Yes, I'm already a dlt user.
Use case
postprocessing rest client responses.
Proposed solution
Expose/add a middleware / interceptor / connection adapter interface to
RESTClient
.If we want to specifically support Pydantic, support for the
TypeAdapter
might be a good way to do it.Related issues
#1593, #1844
The text was updated successfully, but these errors were encountered: