Restful API works at Meteor Shell but not Meteor Methods

Hi Meteorites,

I am using the HTTP.call to make Restful API calls to a third party service provider.

I created relevant Meteor Methods at the server side and call them from the client.

I have no problem for the GET calls. However for POST and PUT calls, it returns Internal server error (500) at client and a 405 Method not allowed at server.

When I tried debugging it, I opened Meteor Shell and calling the POST and PUT calls there, they work. But they don’t when I call the methods from client.

What’s causing this behaviour and how to fix it?

Many thanks.

What kind of Restful api is it, does it need api key? Most likely it doenst allow client side HTTP call, you need to have server side only method to return the results. Unless it is a service that has API keys (stripe, twitter etc…)

The Restful API calls make get service categories (GET), make a service request (POST), cancel or complete a service request (PUT).

It does not need API key but we just randomly create a unique secure code for each call.

The HTTP calls stay inside Meteor Method which is at server. Just have relevant Meteor.call at client side.

How are you returning the results to the client? Show me the callback

Client side

Meteor.call('cancelCall', function (err, res) {
  if (err) {
    console.log(err);
  } else {
    console.log(res);
  }
});

Server Side

Meteor.methods('cancelCall', function () {
 var url = 'http://example.com/some/params/cancel';
 var result = HTTP.call('PUT', url);
 return result;
});

It works at Meteor Shell if I type something like…

HTTP.call('PUT', 'http://example.com/some/params/cancel');

I have no clue… if that methods works fine on server then it should work on stub-only method on client too. Do you have the error message?

At browser console, it returns

M…r.m…e.errorClass {error: 500, reason: "Internal server error", details: undefined, message: "Internal server error [500]", errorType: "Meteor.Error"}

At terminal, it returns

Exception while invoking method 'cancelCall' Error: failed [405] <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>405 Method Not Allowed</title> </head><body> <h1>Method Not Allowed</h1> <p>The requested method PUT is not allowed for the URL /RESTful/some/params/cancel.</p> <hr> <address>Apache Server at beta.seedblooming.com Port 80</address> </body></html>

@sikanx @calvinfu1128 @efrancis @rafaelfaria @system
Hi guys, I build a web service REST API from meteor and the client is native
android java. I wanna upload file from my android using rest or ddp. but
until now, i havent found the solution about uploading file via ddp or
using rest. Anybody wants to help me?