Custom Visualization request /resposne

Hello Team,

I was able to create custom visualization (react visualization) , however i want to execute custom GET /POST requests from the visualization.
I tried to set httpClient from app.js something similar to custom Kibana plugin

const { httpClient } = this.props;
httpClient.get

. but i m getting httpClinet or $http s undefined.

backend.js:1 TypeError: Cannot read property 'get' of undefined

Could you please help me understand how can i execute http GET/POST requests from VisualizationController or react component .

Thank you for your help and support.
Aditya

Hey @adityaPsl,

You can use kfetch to execute GET/POST requests as needed:

import { kfetch } from 'ui/kfetch';

const response = await kfetch({
    pathname: '/api/my-custom-endpoint',
    method: 'POST',
    body: JSON.stringify({ prop1: true, prop2: 'foo' }),
});
1 Like

Thank you very much Larry_Gregory,
I will try to implement this.
Only one query , here pathname is the path we define in server.route function right

Thank you,
Aditya

Hello Larry_Gregory,

Sorry for the delay. kfetch worked for me. only thing is that i had to wrap the kefetch inside async function.

(async () => {
		const response = await kfetch({
			pathname:'../api/sample_react_vis/example',
			method: 'POST',

		  });

Thank you,
Aditya

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.