Skip to content

Commit 2b6f221

Browse files
committed
added postData.params parsing
1 parent 1f68729 commit 2b6f221

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "1.0.0-beta.3",
2+
"version": "1.0.0-beta.4",
33
"name": "httpsnippet",
44
"description": "HTTP Request snippet generator for *most* languages",
55
"main": "./src/index.js",

src/targets/curl.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,15 @@ module.exports = function (options) {
3535
}
3636

3737
// request body
38-
if (this.source.postData) {
39-
code.push(util.format('%s %s', opts.short ? '-d' : '--data', JSON.stringify(this.source.postData.text)));
38+
if (this.source.postData && this.source.postData.text) {
39+
code.push(util.format('%s %s', opts.short ? '-F' : '--form', JSON.stringify(this.source.postData.text)));
40+
}
41+
42+
// construct post params
43+
if (this.source.postData && !this.source.postData.text && this.source.postData.params && this.source.postData.params.length) {
44+
this.source.postData.params.map(function (param) {
45+
code.push(util.format('%s "%s=%s"', opts.short ? '-d' : '--data', param.name, param.value));
46+
});
4047
}
4148

4249
return code.join(opts.indent !== false ? ' \\\n' + opts.indent : ' ');

src/targets/httpie.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = function (options) {
2121
var code = [];
2222

2323
// start with body pipe
24-
if (this.source.postData) {
24+
if (this.source.postData && this.source.postData.text) {
2525
code.push(util.format('echo %s | ', JSON.stringify(this.source.postData.text)));
2626
}
2727

@@ -86,6 +86,13 @@ module.exports = function (options) {
8686
}
8787
}
8888

89+
// construct post params
90+
if (this.source.postData && !this.source.postData.text && this.source.postData.params && this.source.postData.params.length) {
91+
this.source.postData.params.map(function (param) {
92+
code.push(util.format('%s:%s', param.name, param.value));
93+
});
94+
}
95+
8996
// construct headers
9097
if (this.source.headers && this.source.headers.length) {
9198
this.source.headers.map(function (header) {

0 commit comments

Comments
 (0)