I'm working on the project which needs to establish a persistent connection with web-server. I'm planning to use axios like this.
const axiosInstance = axios.create({
baseURL: 'https://httpbin.org/headers',
headers: { 'X-Custom-Header': 'foobar' },
httpsAgent: new https.Agent({
keepAlive: true,
}),
});
axiosInstance
.get()
.then((response) => console.log(response.headers))
.catch((err) => console.log(err.message));
With the get call , the connection is established , but after some calculation or processing I need to break this persistent connection (on-demand basis), is there a way to do this in axios?
Also if this instance of axios axiosInstance gets deleted (the reference of this object goes out of scope and the GC reclaims the memory consumed by it) , will the keep-alive or persistent connection automatically ends with server?