sdkBaseQuery()
function sdkBaseQuery(config?: {
authorization?: string;
baseUrl?: string;
}): BaseQueryFunction;
Base query function for RTK Query integration. Provides automatic error handling, authentication, and token refresh capabilities. Use this as the baseQuery for RTK Query API slices.
Parameters
config?
Configuration options
authorization?
string
Authorization token applied to every request; overrides the session-stored token. Per-endpoint headers still take precedence.
baseUrl?
string
Base URL for API requests
Returns
BaseQueryFunction
RTK Query base query function
Examples
import { createApi } from '@reduxjs/toolkit/query/react';
const api = createApi({
reducerPath: 'api',
baseQuery: sdkBaseQuery({ baseUrl: 'https://api.example.com' }),
endpoints: (builder) => ({
getUser: builder.query({
query: (id) => ({ url: `/users/${id}`, method: 'GET' })
})
})
});
const api = createApi({
reducerPath: 'api',
baseQuery: sdkBaseQuery({
baseUrl: 'https://api.example.com',
authorization: 'Bearer my-custom-token',
}),
endpoints: (builder) => ({
getUser: builder.query({
query: (id) => ({ url: `/users/${id}`, method: 'GET' })
})
})
});
const api = createApi({
reducerPath: 'api',
baseQuery: sdkBaseQuery({ baseUrl: 'https://api.example.com' }),
endpoints: (builder) => ({
getUser: builder.query({
query: (id) => ({
url: `/users/${id}`,
method: 'GET',
headers: { Authorization: 'Bearer per-endpoint-token' },
})
})
})
});