How to connect REST api using Meteorjs

4,578 views
Skip to first unread message

Ashutosh Das

unread,
Nov 12, 2013, 2:43:20 AM11/12/13
to meteo...@googlegroups.com

Suppose my REST root url is

localhost:1000

and URI is " POST /users.json" and parameter are id and key ..

Already I tried this

var result = Meteor.http.call("POST", url, { params: { key: appkey ,id: "xa4" }}) ;
console.log(result);

but it shows ;
[13:34:43.190] Error: Can't make a blocking HTTP call from the client; callback required. @ http://localhost:1000/packages/http.js?4aec4250e79a92408f1c5e234a52434907239586:153

Mitar

unread,
Nov 12, 2013, 3:02:55 AM11/12/13
to meteo...@googlegroups.com
Hi!

You should provide a callback to Meteor.http when using it on the client.


Mitar
> --
> You received this message because you are subscribed to the Google Groups
> "meteor-talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to meteor-talk...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
http://mitar.tnode.com/
https://twitter.com/mitar_m

Ashutosh Das

unread,
Nov 12, 2013, 3:09:09 AM11/12/13
to meteo...@googlegroups.com
Thanks . But I also tried this ....

Meteor.http.call("POST", url, { params: { pio_appkey: appkey ,pio_uid: "xa4" }},function(err,result){
        console.log(result);
      }) ;

But it show  undefined



--
You received this message because you are subscribed to a topic in the Google Groups "meteor-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/meteor-talk/WIAs3MLxyUo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to meteor-talk...@googlegroups.com.

Mitar

unread,
Nov 12, 2013, 3:33:07 AM11/12/13
to meteo...@googlegroups.com
Hi!

And what is in error argument?


Mitar

Ashutosh Das

unread,
Nov 12, 2013, 4:47:45 AM11/12/13
to meteo...@googlegroups.com
Hi ,
Do you mean output of "err" ?
By the way I am following this document http://docs.prediction.io/current/apis/user.html .

Mitar

unread,
Nov 12, 2013, 4:49:40 AM11/12/13
to meteo...@googlegroups.com
Hi!

When you are debugging it is useful to inspect all values you get. If
something does not work, maybe there is an error. Check what it says.


Mitar

Ashutosh Das

unread,
Nov 12, 2013, 4:52:05 AM11/12/13
to meteo...@googlegroups.com
It just shows  [object Error]

Mitar

unread,
Nov 12, 2013, 7:21:27 AM11/12/13
to meteo...@googlegroups.com
Hi!

Click on it.


Mitar

Ashutosh Das

unread,
Nov 12, 2013, 9:18:38 AM11/12/13
to meteo...@googlegroups.com
Inline image 1
google group 2013-11-12 20:15:55.png

gerard sychay

unread,
Nov 12, 2013, 11:46:00 AM11/12/13
to meteo...@googlegroups.com
FWIW, whenever I hit an 3rd-party API, I use the 'request' NPM package. You can use NPM packages in Meteor with the 'npm' meteorite package.


HTH,
Gerard

Abigail Watson

unread,
Nov 12, 2013, 3:02:39 PM11/12/13
to meteo...@googlegroups.com
+1 for 'request'.

If the REST API is chatty or verbose it's response might come over in multiple packets, which means that the receiving node will need to piece together the packets.  So 'request' is better than Http.get() in that regard; but it requires that you run it on the server.  

Before you go down that rabbit hole, however, check that the API is responding correctly to a REST API client.  Make sure there are no proxies, firewalls, etc.  Check the error message like Mi Tar suggests. etc. etc.

https://chrome.google.com/webstore/detail/dev-http-client/aejoelaoggembcahagimdiliamlcdmfm

Mitar

unread,
Nov 12, 2013, 3:17:40 PM11/12/13
to meteo...@googlegroups.com
Hi!

You cannot make HTTP request from the client to another origin just so. That is, you cannot make HTTP requests from the client served from one host (like localhost) to another (like the API host) without the help of that another host.

Read more here:

https://en.wikipedia.org/wiki/Cross-origin_resource_sharing


Mitar
google group 2013-11-12 20:15:55.png

Ashutosh Das

unread,
Nov 12, 2013, 11:16:51 PM11/12/13
to meteo...@googlegroups.com
All of you guys, I really thank you.
Solved the problem.
google group 2013-11-12 20:15:55.png

Mitar

unread,
Nov 13, 2013, 3:10:22 AM11/13/13
to meteo...@googlegroups.com
Hi!

So, what was the problem and what was the solution? It is nice to share with the rest, so that any future reader who come upon this thread over the Internet can know how to fix it as well.


Mitar
google group 2013-11-12 20:15:55.png
Message has been deleted

Ashutosh Das

unread,
Nov 13, 2013, 6:12:17 AM11/13/13
to meteo...@googlegroups.com
Here is the solution :
I run my REST API server in localhost . I just make a mistake that , I call Meteor.http.call from (Meteor.isClient) block. The solution is simple , just call this code from Meteor.isServer block  and return the responce object to Meteor.isClient

Mitar

unread,
Nov 13, 2013, 9:13:10 PM11/13/13
to meteo...@googlegroups.com
Hi!

You have to run on both same host and port number. It is not enough
that you run just on localhost for client side HTTP requests to work.
It is still cross-origin.

Server side does not have this security in place, so this is why you can access.


Mitar

On Wed, Nov 13, 2013 at 3:10 AM, Ashutosh Das <areo...@gmail.com> wrote:
> Here is the solution :
> I run my REST API server in localhost . I just make a mistake that , I call
> Meteor.http.call from (Meteor.isClient) block. The is solution is just call
> this code from Meteor.isServer block :D !

Adrian Lanning

unread,
Nov 13, 2013, 9:44:14 PM11/13/13
to meteo...@googlegroups.com
For those using the 'request' npm package, you may want to check out 'hyperquest':

It introduces a fix for the "5 http calls at a time" limit.  (btw, I read on HN that that limit is fixed in node 0.11)

Arunoda Susiripala

unread,
Nov 17, 2013, 7:57:22 AM11/17/13
to meteo...@googlegroups.com
We can simply remove this limit with.

Npm.require('http').globalAgent.maxSockets = 9999 //to some high value

Arunoda Susiripala

unread,
Nov 17, 2013, 8:06:33 AM11/17/13
to meteo...@googlegroups.com
I think there is no reason to avoid meteor's HTTP unless you need something it doesn't have (like oauth signing, streaming capabilities)
Reply all
Reply to author
Forward
0 new messages