Reading the response from a HTTP REQUEST - anyone?

Anyone figured out how to read the response from a HTTP request yet?

The wiki says:

"If the response body is valid JSON (e.g. “foo”, 23, or [1,2,3]), it will
be parsed and emitted from the “response” output port on the block.
This allows you to asynchronously make requests to external services and
act on the response."

Maybe I’m being an idiot (it happens quite often) but I can’t see how this is supposed to be done. Sorry!


Have it working you need to define an output port

// Output string to web service
local _dsOut = OutputPort(“dsOut”,“string”);

//Send value using pipe as delimiter

Linlk dsOut to HTTP Request Vimp
You can use  to test your posts 

@controlCloud - thanks buddy. I’m doing that just fine - but how to I parse the servers response of that request, back on the imp side of things inside an InputPort handler?

class RespInput extends InputPort
    name = "response";
    type = "string";
    function set(serverresponse)
    {"Our server replied "+serverresponse);
        server.log("SERVER REPLY "+serverresponse);


local input = RespInput("response", "string");

then use the input like


imp.configure("App name", [input], [output]);


drazvan, thanks just assumed you had to use a number as that’s what in Vimp source output type in the planner.

thanks @drazvan @controlCloud.

My code is pretty much exactly the same and so im guessing im doing something else wrong :confused:

my InputPort set method never seems to get called even though im successfully making a http request and am getting a 200 response according to the http request node in the planner.

I’ve tried adding a noodle back to my imp, from the http request node - but still no joy.

Maybe the response from my server needs to be in a particular format or have certain http headers?

I’ve tried a JSON response too rather than just an empty http response as it mentioned this on the wiki - but again no luck.

Here’s a screen grab of my planner view - anybody spot anything obvious? You’ll notice I’ve added a SHOWINPUT node that seems to be displaying my request vars that I’m sending as a parameter in my OutputPort set method.

Here’s my code below, any pointers much appreciated!

class RespInput extends InputPort
    name = “response”;
    type = “string”;
    function set(serverresponse)
    {"Our server replied "+serverresponse);
        server.log("SERVER REPLY "+serverresponse);

local input = RespInput(“response”, “string”);
local output = OutputPort(“request”, “string”);

//then use the input like
imp.configure(“Jon Test”, [input], [output]);“making request…”);

What is your server sending as a response? If you want to send a simple string, just put it between quotes, like “response”. It works fine for me, the server returns a quoted string and I am getting it back in the set()  method of the input port. Content type in my case is text/plain (not sure if that makes a difference).

@drazvan - I’ll try playing with different content types using my own server when I get home and see if that makes a difference, but for the moment the url I’m using is a url that has a content-type of text/html; charset=utf-8 returns and is actually returning “ok”. url below:

One thing I did notice is that I’m currently using POST to make the request but if I change it to GET then I get a http 400 response which is a bit odd and again, maybe points to it being a problem with the content-type or header of the request. Had any experience of this similar issue?

Well, your URL above returns ok (without any quotes around it). You actually need it to return “ok” (with the quotes). 

ok won’t work
"ok" will work

Could you try this?
Hi just tried this and works fine.
I use a Chrome  App Postman REST client to test in bound & then out via imp to

// Output to web service
local _dsOut = OutputPort("dsOut","string");

// Input from web service
class plannerIn extends InputPort
  name = "dsIn"
  type = "string"
  function set(_httpIn)
local _dsIn = plannerIn();

// Register with the server
imp.configure("StringIN", [_dsIn], [_dsOut]);
server.log("Imp-restart - foo - v1.00");"Imp-restart - foo - v1.00");

@controlCloud @drazvan thanks guys for all your help, awesome imp community already :slight_smile:

Your insight helped me figure out that I was pretty much doing the same thing as you guys and pointed me in the direction of the thing that was probably different - my server.

I’ve been using a Google App Engine servlet I wrote to handle the requests and it turns out that App Engine seems to not like my imp requests, because the same servlet works on my dedicated machine. Something in the headers I think.

Hmmm… I’ll figure out exactly what was going on tomorrow and post back just in case anybody else tries this!