We use searchKit client of @searchkit/client in our react application
The search kit config looks like this:
export const searchkitConfig = (authHeaders) => {
const config = {
host: '/api/<URL>/v1/audit',
index: 'in_app_audit',
connectionOptions: {
headers: authHeaders,
},
hits: {
fields: ['category', 'type', 'level', 'message', 'user_email', 'timestamp'],
},
sortOptions: [
{
id: 'timestamp.desc', label: 'Time', field: [{ timestamp: 'desc' }], defaultOption: true,
},
…
I need to wrap are request with an async TokenRequest component. the TokenRequest handles all the token logic, and if the request fails, it sends a request for a new token, then calls the original request again. Here is an example of how we do it in other places in the code:
export async function createAccount(data, messages) {
return tokenRequest({
path: 'asset-service/v1/accounts', method: 'POST', data, messages,
});
}
In general, I could use transporter to add complicated logic, but we don’t do the API request directly with the Searchkit. (Example of using Searchkit directly with transporter:
const response = await Searchkit(skConfig, transporter).execute({
hits: {
from: 0,
size: 10,
}});
instead the code uses useSearchkit from @searchkit/client, and does these requests with this code:
const api = useSearchkit();
api.search();