gitbeaker icon indicating copy to clipboard operation
gitbeaker copied to clipboard

Cache a request response

Open dicolasi opened this issue 1 year ago • 3 comments

Description Hi all, I cannot find anything in documention that suggests how to create a custom requesterFn. In can see that the method signature it expects is (resourceOptions: ResourceOptions) => RequesterType but I cannot even import those types. What I am trying to achieve it to simply use a cache library (like https://www.npmjs.com/package/flat-cache) to check if the data has been already asked, and return it if cache hit... or ask for the data in case of cache miss. If anyone can help would be great (if you have an example I could use even better :) )

I would like to create a custom requesterFn that cache the response.

Checklist

  • [x] I have checked that this is not a duplicate issue.
  • [x] I have read the documentation.

dicolasi avatar Sep 30 '24 11:09 dicolasi

@jdalrymple I would also like to know how to implement a custom requester function. I tried to look through the docs for one because I noticed it was required but didn't find anything. Do you mind posting or linking an example of how this would be done please?

ahedadja avatar Oct 12 '24 00:10 ahedadja

Hi @jdalrymple ,

I also tried creating a custom requesterFn to add some special headers to my calls. After struggling a lot (due to my non-existing typescript skills) I got to create the function but could not handle the response correctly. In the end I could not wrap my head around it and just copied the defaultRequestHandler implementation as it is not exported. Of course this is not very nice, but hey, it works!!! [insert bittersweet smiley here]

So, my questions are:

  • Is there any documentation already available?
  • Are you willing to export the defaultRequestHandler? I saw this was also a topic in this issue https://github.com/jdalrymple/gitbeaker/issues/3403

thanks a lot !

elaine-mattos avatar Jul 02 '25 19:07 elaine-mattos

I was in the process of exporting it nicely, but ran into a whole bunch of other problems which has delayed things considerably. The plan is to do this correctly, I'm sorry it was such a pain to implement :(.

jdalrymple avatar Jul 07 '25 19:07 jdalrymple

yes, without defaultRequestHandler, it's quite hard to implement custom requesterFn

Nick-The-Uncharted avatar Dec 19 '25 09:12 Nick-The-Uncharted