[RTKQ] Inject Multiple Endpoints #4576
Unanswered
jd-carroll
asked this question in
Q&A
Replies: 1 comment
-
Phew... you're the first person to ever ask that, so we don't have a recipe for that. Could you maybe do something like export const warmingModule = (): Module<WarmingModule> => ({
name: warmingModuleName,
init(api, options, context) {
// initialize stuff here if you need to
return {
injectEndpoint(endpoint, definition) {
const anyApi = api as any as Api<
any,
Record<string, any>,
string,
string,
CustomModule | CoreModule
>;
// prevent recursion
if (endpoint.endsWith("Warmer")) return;
anyApi.injectEndpoints(/* the warmer endpoint */);
},
};
},
}); |
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
Uh oh!
There was an error while loading. Please reload this page.
-
Our application is entirely built on AWS Lambda functions and cold starts suck. To help address the cold start problem we've added the ability to "warm" the lambda with a direct API call. So if the normal endpoint is
POST /my/cool-api
the warming endpoint isPOST /my/cool-api -H { x-warming: true }
. The application will generally know when it will potentially need the API so we can issue these warming requests when needed.NOTE: Yes I know about reserved concurrency and that there are lots of details / nuances to whether or not the warming API call will in fact prevent a cold start. But we are working without a budget here so trying to be efficient 😁
Question: Is it possible to change how endpoints are injected into the API such that each "definition" results in two injected endpoints (standard + warmer)?
I'm fairly certain it is, I am just a little lost on the actual implementation. I know I would need to write a custom module, which I think would look something like:
But I'm not sure if that is the correct approach as I can't get the types to work (which is probably a separate question). So, ignoring the types for now, what would be the correct approach to inject an entirely new endpoint?
Beta Was this translation helpful? Give feedback.
All reactions