I've found a fairly simple way to do what I want... It involved quickly setting up a basic express server (set up following this tutorial):
mkdir scratch && cd scratch && npm init
(select defaults except entrypoint app.js)
npm i express
Create an app.js (vi app.js
) with the following contents:
var express = require('express');
var app = express();
var circ = {};
circ.circ = circ;
var cache = [];
app.get('/', function (req, res) {
res.send(JSON.stringify(req, (key, value) => {
if (typeof value === 'object' && value !== null) {
// Duplicate reference found, discard key
if (cache.includes(value)) return;
// Store value in our collection
cache.push(value);
}
return value;
}));
});
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
});
(See this answer for JSON.stringify
custom replacer resp. second argument to JSON.stringify
). You can optionally use flatted instead, which I discovered later and is surely better.
Now do the following:
- Run the app with
node app.js
- In your browser, navigate to the website where your desired request is posted to.
- Open your browsers development tools (Ctrl+shift+c works for me).
- Go to the network tab.
- Find the request that interests you and right click on it.
- Click on copy > copy as curl (or similar, depending on which browser you're using).
- Run that
curl
request, but change the url it's posted to to 127.0.0.1:3000
(e.g. change curl 'example.com' \...etc
to curl '127.0.0.1:3000' \...etc
You should now get that request on standard output as a JSON object and it's in the format that express usually deals with. Yay! Now, pipe it into your clipboard (likely xclip -selection c
on linux) or probably even better, redirect it to a file.
...
Step 2 - ?
Step 3 - Profit :)