Reputation: 3
I would like to access requestId that RTK generate for maintaining the cache for every request it fires and send it as a header under x-request-id.
Here's my slice
export const api = createApi({
reducerPath: 'api',
baseQuery: fetchBaseQuery({
baseUrl: 'http://localhost:9000',
prepareHeaders: (headers, { requestId }) => {
headers.set('x-request-id', requestId)
},
}),
endpoints: (builder) => ({
getPage: builder.query<PageResponse, PageRequest>({
query: (pageRequest) => {
return {
url: '/api/4/page/fetch',
body: pageRequest,
method: 'POST',
};
},
}),
})
});
Is there a way we can access the requestId
to be sent along in request headers?
See type UseQueryResult<T>
here
Upvotes: 0
Views: 831