Replies: 3 comments 1 reply
-
@nuhhtyy While reqwest doesn't support middleware/interceptor, you can use the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Coming from Axios, when sending http requests that require some type of header computed at runtime the interceptors can be useful
for instance an auth header that includes the current timestamp
while you can add headers on a
RequestBuilder
, its kind of difficult to extract information from the actual request, mostly because the fields/useful fns are private, and nothing implements the copy traitfor context heres an example of something i need to do
X-HMAC is defined as the time current unix timestamp, + path + (if applicable the JSON string of) body
and
X-TIMESTAMP is just the timestamp
while i could do
instead of doing all this work before each call instead im just doing a request builder doing a
.build()
to get the request and extracting the data from the request and computing the headersso im left with a request object (which contains all the information i need), but i cant go back into a builder because the fields and the
new
function is privateidea: make these fields and functions public, and add an interceptor field to a RequestBuilder, that gets called in
.send()
by making the Request field public and implementing clone, I can extract the info and add the headers on multiple routes with a single function defintion
this behaviour should be specific to the
Client
instance (ie interceptors are defined when the client is instantiated)Beta Was this translation helpful? Give feedback.
All reactions