Meteor Js : Calling a REST Service

In this example I will show how to call a REST service and parse this results to JSON format.


Function implementation

var restServiceCall = function (url) {
    var result = HTTP.get(url, {
        headers: parseHeaders,
        params: getParseParams()

    if (result.statusCode == 200) {
        return JSON.parse(result.content).results;
    } else {
        var json = JSON.parse(result.content);
        throw new Meteor.Error(result.statusCode, json.error);

Using my function

Now I will have a array of objects in JSON format.

var myArrayObjects = restServiceCall('https://restServiceCall/param/1');


  1. Hi, thanks a lot for your code! 😀
    I’m encountering a problem, and maybe you can help me out a bit >_<

    I tried running this code client-side:
    but I got the error "Can't make a blocking HTTP call from the client; callback required"

    so I tried running this other code:
    and instead I get the error "Cannot read property '0' of undefined"

    Any word of advice? 🙂


  2. I’m really enjoying the design and layout of your website.
    It’s a very easy on the eyes which makes it much more enjoyable for
    me to come here and visit more often. Did you hire out a
    developer to create your theme? Superb work!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s