Hi, I have a question about asynchroneous calls to 3rd party APIs with Meteor. This is what I’m trying to achieve:
The user enters some information in the client (actually, it’s a Cordova app, but I don’t think this matters in this case; I’m sending the data from Cordova to the web client via handleOpenURL).
The information the user enters shall trigger a request to a 3rd party database via a REST API. This data retrieval should happen on the server side (in order to not disclose the API keys to the
After the REST API call retrieved a result, the result data should be further enriched by the server. The server will mirror the (enriched) data in its own database, so further clients will be served with this enriched data without calling the REST API again (for the same input data).
Also, the server shall perform some additional calulations to prepare result data in a proper way for the client. Then, this polished result shall be returned back to the client.
The client template should display the results using a Spacebars template.
In the Meteor docs I can only find “simpler” scenarios where the data is already available in the MongoDB and the client can “just” subscribe to it. But I cannot find a sample that also involves a more complex roundtrip involving 3rd party API calls.
I’m especially wondering how I can manage the asynchroneous call and how to handle the time delays caused by them in a proper way. I guess this is a case for .wrapAsync(), but I’m not quite sure, since Meteor also seems to have some API’s which hide this complexity by “imitating” synchroneous calls. I’ve read a lot of forum threads and docs I’ve found on stackoverflow, but these tend to deal with only a “part of the story” (i.e. how to call .wrapAsync() properly), they did not give me the “big picture” (i.e. do I even need .wrapAsync(), or is there a more elegant solution to my problem like the http methods provided by core?) - And how exactly to set-up the communication between client, server and the API call in a kind of “best practice” way.
BTW: I’m using FlowRouter for the routing tasks and would like to display a kind of “Loading” spinner on the client until the roundtrip has succeeded. Any hints / links to sample code would be appreciated!