Sending data from client.js to home.html WITHOUT collections


#1

Hi Guys,
I’m a meteor newbie, and I’m working at a project that makes HTTP calls to external APIs.
From these calls I get an array of strings (html codes, to be more specific) that I wish to display onto my html.
I know how to use templates but in this case, it will just slow down the workflow and besides that it seems dumb to save all search results in a DB just to display it to the client.
So the question is: How can I ‘send’ the strings from ‘results’ to the home.html and display it, without a collection.

This is the method from the client.js and that returns the array of strings:
Meteor.call('tweeterSearch', '#' + text, function (err, results) { if (!err){ console.log(results); } })

Sorry if my question seems stupid or if the topic preexists. I’ve searched before postin this and all I’ve found were problems that others encountered about communication between client and server when using templates…

EDIT:
I meant collections, not templates


#2

I think your question is confusing templates with collections. If not, I apologise, but you will need to use templates to render your data. On the other hand, for getting your API data to the client if you don’t want to save to the DB, you basically have two options:

  1. Use Meteor methods on the server, with corresponding calls on the client (not really reactive).
  2. Do something like this: Best Way to handle a 3rd Party endpoint

#3

@robfallows I’m using meteor methods to make the rest api calls in the server, but this is not the point. I just want to -let’s say- ‘output’ the value found in results on the html page without using collections. Can I do that? If yes, how?


#4

Yes, you can but you need to use templates, because you will need to use a template helper (your post title demands WITHOUT templates). The point I was making about client-side collections is they do not exist on the server, and so are not stored in the DB. On the other hand, they are really handy for this sort of use case.


#5

just use the HTTP package if that is what you so desire.

Template.yourTemplate.onCreated(function () {
  var instance = this;
  HTTP.get('http://someresource/resource/id', function (err, data) {
    instance.data = data;
  });
});

#6

@robfallows So the client-side collection gets the data directly from the server and does’t store it in the db. After that, I can put it in a template and output it onto the html, right? Or did I get it wrong :smiley:
Also, I’ve changed the title of the thread.
Thanks a lot, btw!


#7

That’s exactly right. Thanks for changing the title - it was confusing. :smile: