It would be interesting to know what you are trying to get server side. If you have access to your apiURL and can manage CORS and you call from the server just to then send the info the client, it is best to fetch it directly on the client.
On the server it is best to do POST and leave it but GETs can affect user or server experience if the API you call is slow or buggy.
You have an example here: fetch | Meteor API Docs
From your async function of your method you would return the result of the last line (in the documentation)
You might also want to use AbortController() to abort the operation afte x seconds such as:
import { Meteor } from 'meteor/meteor';
import { fetch, Headers } from 'meteor/fetch';
import { fetch } from 'meteor/fetch'
import AbortController from 'abort-controller'
const controller = new AbortController()
const timeout = setTimeout(() => {
controller.abort()
}, 1000) // cancel call after 1 second
async function postData (url, data) {
try {
const response = await fetch(url, {
signal: controller.signal
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: new Headers({
Authorization: 'Bearer my-secret-key',
'Content-Type': 'application/json'
}),
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(data) // body data type must match "Content-Type" header
});
const data = await response.json();
return response(null, data);
} catch (err) {
return response(err, null);
}
}
const postDataCall = Meteor.wrapAsync(postData);
return postDataCall('https://www.example.org/statsSubmission', { totalUsers: 55 }))