I don't think using HAProxy for calling 3rd party APIs is normal. I don't think there is any issue with either of your current tools, but I would use axios because you can create specialized sub-instances (perfect for APIs!).
const instance = axios.create({
baseURL: 'some-api-domain.com/api',
timeout: 1000,
headers: {'X-Custom-Header': 'foobar'}
});
// every HTTP request made using the instance object
// will include the specified defaults
export default instance
// other file
import someApi from './some-api'
export async function getContacts() {
const response = await someApi.get("contacts")
return response.data
}
export async function addContact(data) {
const response = await someApi.post("contacts", data)
return response.data
}
export async function getContact(id) {
const response = await someApi.get(`contacts/${id}`)
return response.data
}
Axios is isomorphic (works in browser and in serverside), also checkout the middlewares (called interceptors).
I recommend not using fetch because fetch is very low-level and does almost nothing right by default for typical 3rd party JSON APIs. medium.com/@shahata/why-i-wont-be-using-fetch-api…