Created
August 27, 2015 12:45
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi