bruno icon indicating copy to clipboard operation
bruno copied to clipboard

feat: save request/response history (including between launches)

Open cvmocanu opened this issue 1 year ago • 10 comments

Insomnia saves all the requests that were done. This history persists even if we restart Insomnia. This is a very useful feature when you want to have a quick look at how a response body looks.

One feature that Insomnia doesn't have (but which Postman has), and is very useful, is the ability to give a name to the request/response history entry.

Also, since the requests and responses may contain sensitive data, they shouldn't be saved in the collection directory, but outside of it, only on the local machine, just as Bruno handles secret environment variables.

cvmocanu avatar Oct 06 '23 08:10 cvmocanu

i need this for my current project so bad, that i gave in and signed up for insomnia. I have long running tasks that take up over 100 seconds and with bruno on error i only get a pop up that shows for 2 seconds without any real information and thats it. If i want to see it again i have to redo the request and wait again, what a bummer.

carlonoelle avatar Oct 09 '23 18:10 carlonoelle

@carlonoelle

We'll support History very soon. Meanwhile I can suggest a workaround. In the v0.22.0 release, we have released support for collection level scripting. And you can log you response in the collection post script for debugging purpose. Here is our scripting docs: https://docs.usebruno.com/scripting/javascript-reference.html

Can you check and see if this is of any help?

image

helloanoop avatar Oct 09 '23 21:10 helloanoop

Thanks @helloanoop, for now that helps. That it is on the roadmap is good to know though since console is not persistent,

carlonoelle avatar Oct 10 '23 13:10 carlonoelle

since console is not persistent

@carlonoelle here is one neat hack of using post response scripting in the collection level. You just need to create a logs directory inside your collection root folder and every request-response will get saved here.

const fs = require('fs');
const path = require('path');
const moment = require('moment');

const safeStringify = function (obj) {
  try {
    return JSON.stringify(obj, null, 2);
  } catch (err) {
    return obj
  }
};

const request = {
  url: req.getUrl(),
  headers: req.getHeaders(),
  method: req.getMethod(),
  body: req.getBody()
};

const response = {
  status: res.getStatus(),
  headers: res.getHeaders(),
  body: res.getBody()
};

const now = moment();
const formattedDate = now.format('YYYYMMDD-HHmmss');
const filename = path.join(bru.cwd(), 'logs', `${formattedDate}.json`);
const content = safeStringify({request, response}, null, 2);

fs.writeFileSync(filename, content);

You also need to add the scripts field in your bruno.json at the root of collection to allow fs access

{
   "scripts": {
    "filesystemAccess": {
      "allow": true
    }
  }
}

helloanoop avatar Oct 10 '23 21:10 helloanoop

any progress?

izturn avatar Dec 12 '23 02:12 izturn

I like the suggested work around @helloanoop but I am getting an error (on Windows) Error invoking remote method 'send-http-request': VMError: Module 'C:\Users\xxx\AppData\Local\Programs\bruno\fs' is not allowed to be required. The path is outside the border!

Nevermind, I found this info about setting bruno to allow file system access: https://github.com/usebruno/bruno/discussions/385#discussioncomment-7246390 Logging is working now :)

testmonger avatar Jan 09 '24 14:01 testmonger

@testmonger Please also add the scripts field in your bruno.json at the root of collection to fix the filesystem issue

{
   "scripts": {
    "filesystemAccess": {
      "allow": true
    }
  }
}

helloanoop avatar Jan 09 '24 15:01 helloanoop

Any progress here? Persistent request history would be very useful.

oklaiss avatar Apr 09 '24 17:04 oklaiss

@helloanoop @sanjai0py Is anyone working on this issue from your side? If not, could you assign this to me. I can start working on it.

lanthoor avatar May 14 '24 07:05 lanthoor

@helloanoop @sanjai0py Is anyone working on this issue from your side? If not, could you assign this to me. I can start working on it.

This feature is already implemented in the Golden Edition

Its-treason avatar May 14 '24 08:05 Its-treason