Skip to content

Instantly share code, notes, and snippets.

@lukehorvat
Created August 27, 2015 12:45
Show Gist options
  • Save lukehorvat/9727016797489df0523e to your computer and use it in GitHub Desktop.
Save lukehorvat/9727016797489df0523e to your computer and use it in GitHub Desktop.
Express middleware to log a JSON request as a cURL command. Inspired by Chrome's "Copy as cURL" feature.
// After body-parsing middleware...
app.use(function(req, res, next) {
console.log(
"curl '%s://%s%s' -X %s -H 'Content-Type: %s' -d '%s'",
req.protocol,
req.get("host"),
req.originalUrl,
req.method,
req.get("Content-Type"),
JSON.stringify(req.body)
);
next();
});
@hacknlove
Copy link

the rest of the headers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment