Http: how to show the complete request and response objects


#1

Hi,

I am making a app to show the interactions between Meteor and another system which communicate via REST HTTP calls. Is there any way I can store the final http request in an object?

So the student can see

  1. This is what I send to the server
  2. This is what it return to me
export function copyApp(guid, name) {
    check(guid, String);
    check(name, String);
    console.log('QRS sync Functions Appp, copy the app id' + guid + 'to app with name: ', name);

    try {
        const result = HTTP.post('http://' + config.host + '/' + config.virtualProxy + '/qrs/app/' + guid + '/copy?', {
            headers: authHeaders,
            params: { 'xrfkey': config.xrfkey, 'name': name },
            data: { "name": name }
        })
        return result;
    } catch (err) {
        throw new Meteor.Error('Copy app for selected customers failed', err.message);
    }
};

#2

Meteor’s HTTP package doesn’t support request logging directly. On the server though it really just wraps the npm request package. The request package does support request logging, so one option might be to use request on the server instead of HTTP. You would do this and enable full request/response logging like:

const request = require('request');
request.debug = true;
...
const result = request.post('...');
...

Request/response output will then be dumped to your console. This might not be ideal in your case though since it doesn’t cover both client/server (and it’s not showing students how to use the HTTP package, but the package behind the package … which might be a good thing with the upcoming move to npm …), but it’s an option.


#3

Hey, that sounds as a solution. What I will then do is

  1. use the npm module
  2. store the request and response in mongo

thank you