httpsnippet
Advanced tools
Comparing version 1.16.2 to 1.16.3
{ | ||
"version": "1.16.2", | ||
"version": "1.16.3", | ||
"name": "httpsnippet", | ||
@@ -8,4 +8,4 @@ "description": "HTTP Request snippet generator for *most* languages", | ||
"license": "MIT", | ||
"main": "./src/index.js", | ||
"bin": "./bin/httpsnippet", | ||
"main": "src/index.js", | ||
"bin": "bin/httpsnippet", | ||
"keywords": [ | ||
@@ -45,6 +45,3 @@ "api", | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/Mashape/httpsnippet" | ||
}, | ||
"repository": "Mashape/httpsnippet", | ||
"bugs": { | ||
@@ -54,5 +51,7 @@ "url": "https://github.com/Mashape/httpsnippet/issues" | ||
"scripts": { | ||
"test": "standard && mocha --no-timeouts --reporter spec --fgrep 'Request Validation' --invert", | ||
"travis": "standard && mocha --no-timeouts --reporter spec", | ||
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- --fgrep 'Request Validation' --invert", | ||
"quick": "mocha --no-timeouts --fgrep 'Request Validation' --invert", | ||
"pretest": "standard && echint", | ||
"test": "mocha --no-timeouts", | ||
"posttest": "npm run coverage", | ||
"coverage": "istanbul cover --dir coverage _mocha -- --fgrep 'Request Validation' --invert -R dot", | ||
"codeclimate": "codeclimate < coverage/lcov.info" | ||
@@ -65,20 +64,28 @@ }, | ||
}, | ||
"echint": { | ||
"ignore": [ | ||
"coverage/**", | ||
"CONTRIBUTING.md", | ||
"test/fixtures/**" | ||
] | ||
}, | ||
"devDependencies": { | ||
"codeclimate-test-reporter": "0.0.4", | ||
"glob": "^5.0.3", | ||
"istanbul": "^0.3.13", | ||
"mocha": "^2.2.1", | ||
"should": "^5.2.0", | ||
"standard": "^3.3.0" | ||
"codeclimate-test-reporter": "0.1.0", | ||
"echint": "^1.5.0", | ||
"glob": "^5.0.14", | ||
"istanbul": "^0.3.17", | ||
"mocha": "^2.2.5", | ||
"should": "^7.0.2", | ||
"standard": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"async": "^0.9.0", | ||
"chalk": "^1.0.0", | ||
"commander": "^2.7.1", | ||
"debug": "^2.1.3", | ||
"event-stream": "^3.3.0", | ||
"form-data": "^0.2.0", | ||
"har-validator": "^1.5.1", | ||
"require-directory": "^2.1.0" | ||
"bluebird": "^2.9.34", | ||
"chalk": "^1.1.0", | ||
"commander": "^2.8.1", | ||
"debug": "^2.2.0", | ||
"event-stream": "^3.3.1", | ||
"form-data": "^1.0.0-rc3", | ||
"har-validator": "^1.8.0", | ||
"require-directory": "^2.1.1" | ||
} | ||
} |
# HTTP Snippet [![version][npm-version]][npm-url] [![License][npm-license]][license-url] | ||
HTTP Request snippet generator for *many* languages & tools including: `cURL`, `HTTPie`, `Javascript`, `Node`, `C`, `Java`, `PHP`, `Objective-C`, `Swift`, `Python`, `Ruby`, `C#`, `Go`, `OCaml` and [more](https://github.com/Mashape/httpsnippet/wiki/Targets)! | ||
> HTTP Request snippet generator for *many* languages & tools including: `cURL`, `HTTPie`, `Javascript`, `Node`, `C`, `Java`, `PHP`, `Objective-C`, `Swift`, `Python`, `Ruby`, `C#`, `Go`, `OCaml` and [more](https://github.com/Mashape/httpsnippet/wiki/Targets)! | ||
@@ -39,3 +39,2 @@ Relies on the popular [HAR](http://www.softwareishard.com/blog/har-12-spec/#request) format to import data and describe HTTP calls. | ||
-o, --output <directory> write output to directory | ||
-n, --output-name <name> output file name | ||
@@ -42,0 +41,0 @@ ``` |
@@ -14,3 +14,3 @@ 'use strict' | ||
// constructor | ||
var HTTPSnippet = function (data, lang) { | ||
var HTTPSnippet = function (data) { | ||
var entries | ||
@@ -32,3 +32,3 @@ var self = this | ||
entries.map(function (entry) { | ||
entries.forEach(function (entry) { | ||
// add optional properties to make validation successful | ||
@@ -48,4 +48,2 @@ entry.request.httpVersion = entry.request.httpVersion || 'HTTP/1.1' | ||
if (!valid) { | ||
debug(err) | ||
throw err | ||
@@ -116,3 +114,3 @@ } | ||
request.postData.params.map(function (param) { | ||
request.postData.params.forEach(function (param) { | ||
form.append(param.name, param.value || '', { | ||
@@ -204,3 +202,3 @@ filename: param.fileName || null, | ||
var results = this.requests.map(function (request) { | ||
return func.call(null, request, opts) | ||
return func(request, opts) | ||
}) | ||
@@ -207,0 +205,0 @@ |
@@ -21,3 +21,3 @@ 'use strict' | ||
headers.map(function (key) { | ||
headers.forEach(function (key) { | ||
code.push('headers = curl_slist_append(headers, "%s: %s");', key, source.headersObj[key]) | ||
@@ -24,0 +24,0 @@ }) |
@@ -21,3 +21,3 @@ 'use strict' | ||
if (headers.length) { | ||
headers.map(function (key) { | ||
headers.forEach(function (key) { | ||
code.push('request.AddHeader("%s", "%s");', key, source.headersObj[key]) | ||
@@ -24,0 +24,0 @@ }) |
@@ -22,2 +22,3 @@ /** | ||
var opts = util._extend({ | ||
showBoilerplate: true, | ||
checkErrors: false, | ||
@@ -30,7 +31,9 @@ printBody: true, | ||
var indent = opts.showBoilerplate ? 1 : 0 | ||
var errorCheck = function () { | ||
if (opts.checkErrors) { | ||
code.push(1, 'if err != nil {') | ||
.push(2, 'panic(err)') | ||
.push(1, '}') | ||
code.push(indent, 'if err != nil {') | ||
.push(indent + 1, 'panic(err)') | ||
.push(indent, '}') | ||
} | ||
@@ -40,25 +43,27 @@ } | ||
// Create boilerplate | ||
code.push('package main') | ||
if (opts.showBoilerplate) { | ||
code.push('package main') | ||
.blank() | ||
.push('import (') | ||
.push(1, '"fmt"') | ||
.push(indent, '"fmt"') | ||
if (opts.timeout > 0) { | ||
code.push(1, '"time"') | ||
} | ||
if (opts.timeout > 0) { | ||
code.push(indent, '"time"') | ||
} | ||
if (source.postData.text) { | ||
code.push(1, '"strings"') | ||
} | ||
if (source.postData.text) { | ||
code.push(indent, '"strings"') | ||
} | ||
code.push(1, '"net/http"') | ||
code.push(indent, '"net/http"') | ||
if (opts.printBody) { | ||
code.push(1, '"io/ioutil"') | ||
} | ||
if (opts.printBody) { | ||
code.push(indent, '"io/ioutil"') | ||
} | ||
code.push(')') | ||
code.push(')') | ||
.blank() | ||
.push('func main() {') | ||
.blank() | ||
} | ||
@@ -69,6 +74,6 @@ // Create client | ||
client = 'client' | ||
code.push(1, 'client := http.Client{') | ||
.push(2, 'Timeout: time.Duration(%s * time.Second),', opts.timeout) | ||
.push(1, '}') | ||
.blank() | ||
code.push(indent, 'client := http.Client{') | ||
.push(indent + 1, 'Timeout: time.Duration(%s * time.Second),', opts.timeout) | ||
.push(indent, '}') | ||
.blank() | ||
} else { | ||
@@ -78,14 +83,14 @@ client = 'http.DefaultClient' | ||
code.push(1, 'url := "%s"', source.fullUrl) | ||
.blank() | ||
code.push(indent, 'url := "%s"', source.fullUrl) | ||
.blank() | ||
// If we have body content or not create the var and reader or nil | ||
if (source.postData.text) { | ||
code.push(1, 'payload := strings.NewReader(%s)', JSON.stringify(source.postData.text)) | ||
.blank() | ||
.push(1, 'req, %s := http.NewRequest("%s", url, payload)', errorPlaceholder, source.method) | ||
.blank() | ||
code.push(indent, 'payload := strings.NewReader(%s)', JSON.stringify(source.postData.text)) | ||
.blank() | ||
.push(indent, 'req, %s := http.NewRequest("%s", url, payload)', errorPlaceholder, source.method) | ||
.blank() | ||
} else { | ||
code.push(1, 'req, %s := http.NewRequest("%s", url, nil)', errorPlaceholder, source.method) | ||
.blank() | ||
code.push(indent, 'req, %s := http.NewRequest("%s", url, nil)', errorPlaceholder, source.method) | ||
.blank() | ||
} | ||
@@ -97,5 +102,6 @@ | ||
if (Object.keys(source.allHeaders).length) { | ||
Object.keys(source.allHeaders).map(function (key) { | ||
code.push(1, 'req.Header.Add("%s", "%s")', key, source.allHeaders[key]) | ||
Object.keys(source.allHeaders).forEach(function (key) { | ||
code.push(indent, 'req.Header.Add("%s", "%s")', key, source.allHeaders[key]) | ||
}) | ||
code.blank() | ||
@@ -105,3 +111,3 @@ } | ||
// Make request | ||
code.push(1, 'res, %s := %s.Do(req)', errorPlaceholder, client) | ||
code.push(indent, 'res, %s := %s.Do(req)', errorPlaceholder, client) | ||
errorCheck() | ||
@@ -112,4 +118,4 @@ | ||
code.blank() | ||
.push(1, 'defer res.Body.Close()') | ||
.push(1, 'body, %s := ioutil.ReadAll(res.Body)', errorPlaceholder) | ||
.push(indent, 'defer res.Body.Close()') | ||
.push(indent, 'body, %s := ioutil.ReadAll(res.Body)', errorPlaceholder) | ||
errorCheck() | ||
@@ -120,11 +126,13 @@ } | ||
code.blank() | ||
.push(1, 'fmt.Println(res)') | ||
.push(indent, 'fmt.Println(res)') | ||
if (opts.printBody) { | ||
code.push(1, 'fmt.Println(string(body))') | ||
code.push(indent, 'fmt.Println(string(body))') | ||
} | ||
// End main block | ||
code.blank() | ||
if (opts.showBoilerplate) { | ||
code.blank() | ||
.push('}') | ||
} | ||
@@ -131,0 +139,0 @@ return code.join() |
@@ -23,8 +23,8 @@ /** | ||
var methods = [ 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'] | ||
var methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD'] | ||
var methodsWithBody = [ 'POST', 'PUT', 'DELETE', 'PATCH'] | ||
var methodsWithBody = ['POST', 'PUT', 'DELETE', 'PATCH'] | ||
code.push('OkHttpClient client = new OkHttpClient();') | ||
.blank() | ||
.blank() | ||
@@ -34,3 +34,3 @@ if (source.postData.text) { | ||
code.push('MediaType mediaType = MediaType.parse("%s; boundary=%s");', source.postData.mimeType, source.postData.boundary) | ||
}else { | ||
} else { | ||
code.push('MediaType mediaType = MediaType.parse("%s");', source.postData.mimeType) | ||
@@ -46,3 +46,3 @@ } | ||
code.push(1, '.method("%s", body)', source.method.toUpperCase()) | ||
}else { | ||
} else { | ||
code.push(1, '.method("%s", null)', source.method.toUpperCase()) | ||
@@ -53,3 +53,3 @@ } | ||
code.push(1, '.%s(body)', source.method.toLowerCase()) | ||
}else { | ||
} else { | ||
code.push(1, '.%s(null)', source.method.toLowerCase()) | ||
@@ -66,3 +66,3 @@ } | ||
if (headers.length) { | ||
headers.map(function (key) { | ||
headers.forEach(function (key) { | ||
code.push(1, '.addHeader("%s", "%s")', key, source.allHeaders[key]) | ||
@@ -73,4 +73,4 @@ }) | ||
code.push(1, '.build();') | ||
.blank() | ||
.push('Response response = client.newCall(request).execute();') | ||
.blank() | ||
.push('Response response = client.newCall(request).execute();') | ||
@@ -77,0 +77,0 @@ return code.join() |
@@ -36,3 +36,3 @@ /** | ||
if (headers.length) { | ||
headers.map(function (key) { | ||
headers.forEach(function (key) { | ||
code.push(1, '.header("%s", "%s")', key, source.allHeaders[key]) | ||
@@ -39,0 +39,0 @@ }) |
@@ -44,3 +44,3 @@ /** | ||
source.postData.params.map(function (param) { | ||
source.postData.params.forEach(function (param) { | ||
code.push('form.append(%s, %s);', JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || '')) | ||
@@ -47,0 +47,0 @@ }) |
@@ -33,3 +33,3 @@ /** | ||
source.postData.params.map(function (param) { | ||
source.postData.params.forEach(function (param) { | ||
code.push('data.append(%s, %s);', JSON.stringify(param.name), JSON.stringify(param.value || param.fileName || '')) | ||
@@ -66,3 +66,3 @@ }) | ||
Object.keys(source.allHeaders).map(function (key) { | ||
Object.keys(source.allHeaders).forEach(function (key) { | ||
code.push('xhr.setRequestHeader(%s, %s);', JSON.stringify(key), JSON.stringify(source.allHeaders[key])) | ||
@@ -69,0 +69,0 @@ }) |
@@ -96,3 +96,3 @@ /** | ||
source.cookies.map(function (cookie) { | ||
source.cookies.forEach(function (cookie) { | ||
code.push('jar.setCookie(request.cookie("%s=%s"), "%s");', encodeURIComponent(cookie.name), encodeURIComponent(cookie.value), url) | ||
@@ -99,0 +99,0 @@ }) |
@@ -64,6 +64,8 @@ 'use strict' | ||
return '@{ ' + keyValuePairs.join(join) + ' }' | ||
case '[object Boolean]': | ||
return value ? '@YES' : '@NO' | ||
default: | ||
return '@"' + value.replace(/"/g, '\\"') + '"' | ||
return '@"' + value.toString().replace(/"/g, '\\"') + '"' | ||
} | ||
} | ||
} |
@@ -38,3 +38,3 @@ /** | ||
headers.map(function (key) { | ||
headers.forEach(function (key) { | ||
code.push(1, '("%s", "%s");', key, source.allHeaders[key]) | ||
@@ -41,0 +41,0 @@ }) |
@@ -31,7 +31,7 @@ /** | ||
code.push(opts.shortTags ? '<?' : '<?php') | ||
.blank() | ||
.blank() | ||
} | ||
code.push('$curl = curl_init();') | ||
.blank() | ||
.blank() | ||
@@ -42,31 +42,31 @@ var curlOptions = [{ | ||
value: source.uriObj.port | ||
}, { | ||
}, { | ||
escape: true, | ||
name: 'CURLOPT_URL', | ||
value: source.fullUrl | ||
}, { | ||
}, { | ||
escape: false, | ||
name: 'CURLOPT_RETURNTRANSFER', | ||
value: 'true' | ||
}, { | ||
}, { | ||
escape: true, | ||
name: 'CURLOPT_ENCODING', | ||
value: '' | ||
}, { | ||
}, { | ||
escape: false, | ||
name: 'CURLOPT_MAXREDIRS', | ||
value: opts.maxRedirects | ||
}, { | ||
}, { | ||
escape: false, | ||
name: 'CURLOPT_TIMEOUT', | ||
value: opts.timeout | ||
}, { | ||
}, { | ||
escape: false, | ||
name: 'CURLOPT_HTTP_VERSION', | ||
value: source.httpVersion === 'HTTP/1.0' ? 'CURL_HTTP_VERSION_1_0' : 'CURL_HTTP_VERSION_1_1' | ||
}, { | ||
}, { | ||
escape: true, | ||
name: 'CURLOPT_CUSTOMREQUEST', | ||
value: source.method | ||
}, { | ||
}, { | ||
escape: true, | ||
@@ -81,3 +81,3 @@ name: 'CURLOPT_POSTFIELDS', | ||
curlOptions.map(function (option) { | ||
curlOptions.forEach(function (option) { | ||
if (!~[null, undefined].indexOf(option.value)) { | ||
@@ -104,15 +104,15 @@ curlopts.push(util.format('%s => %s,', option.name, option.escape ? JSON.stringify(option.value) : option.value)) | ||
curlopts.push('CURLOPT_HTTPHEADER => array(') | ||
.push(1, headers.join(',\n' + opts.indent + opts.indent)) | ||
.push('),') | ||
.push(1, headers.join(',\n' + opts.indent + opts.indent)) | ||
.push('),') | ||
} | ||
code.push(1, curlopts.join()) | ||
.push('));') | ||
.blank() | ||
.push('$response = curl_exec($curl);') | ||
.push('$err = curl_error($curl);') | ||
.blank() | ||
.push('curl_close($curl);') | ||
.blank() | ||
.push('if ($err) {') | ||
.push('));') | ||
.blank() | ||
.push('$response = curl_exec($curl);') | ||
.push('$err = curl_error($curl);') | ||
.blank() | ||
.push('curl_close($curl);') | ||
.blank() | ||
.push('if ($err) {') | ||
@@ -126,8 +126,8 @@ if (opts.namedErrors) { | ||
code.push('} else {') | ||
.push(1, 'echo $response;') | ||
.push('}') | ||
.push(1, 'echo $response;') | ||
.push('}') | ||
if (!opts.noTags && opts.closingTag) { | ||
code.blank() | ||
.push('?>') | ||
.push('?>') | ||
} | ||
@@ -134,0 +134,0 @@ |
@@ -30,3 +30,3 @@ 'use strict' | ||
obj.map(function (item) { | ||
obj.forEach(function (item) { | ||
result.push(convert(item, indent + indent, indent)) | ||
@@ -33,0 +33,0 @@ }) |
@@ -40,3 +40,3 @@ 'use strict' | ||
if (headers.length) { | ||
headers.map(function (key) { | ||
headers.forEach(function (key) { | ||
code.push('request["%s"] = \'%s\'', key, source.allHeaders[key]) | ||
@@ -43,0 +43,0 @@ }) |
@@ -33,3 +33,3 @@ /** | ||
// construct headers | ||
Object.keys(source.headersObj).sort().map(function (key) { | ||
Object.keys(source.headersObj).sort().forEach(function (key) { | ||
var header = util.format('%s: %s', key, source.headersObj[key]) | ||
@@ -36,0 +36,0 @@ code.push('%s %s', opts.short ? '-H' : '--header', helpers.quote(header)) |
@@ -78,7 +78,7 @@ /** | ||
queryStringKeys.map(function (name) { | ||
queryStringKeys.forEach(function (name) { | ||
var value = source.queryObj[name] | ||
if (util.isArray(value)) { | ||
value.map(function (val) { | ||
value.forEach(function (val) { | ||
code.push('%s==%s', name, helpers.quote(val)) | ||
@@ -93,3 +93,3 @@ }) | ||
// construct headers | ||
Object.keys(source.allHeaders).sort().map(function (key) { | ||
Object.keys(source.allHeaders).sort().forEach(function (key) { | ||
code.push('%s:%s', key, helpers.quote(source.allHeaders[key])) | ||
@@ -103,3 +103,3 @@ }) | ||
source.postData.params.map(function (param) { | ||
source.postData.params.forEach(function (param) { | ||
code.push('%s=%s', param.name, helpers.quote(param.value)) | ||
@@ -106,0 +106,0 @@ }) |
@@ -34,3 +34,3 @@ /** | ||
Object.keys(source.allHeaders).map(function (key) { | ||
Object.keys(source.allHeaders).forEach(function (key) { | ||
var header = util.format('%s: %s', key, source.allHeaders[key]) | ||
@@ -37,0 +37,0 @@ code.push('--header %s', helpers.quote(header)) |
@@ -74,6 +74,8 @@ 'use strict' | ||
return concatArray(keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel) | ||
case '[object Boolean]': | ||
return value.toString() | ||
default: | ||
return '"' + value.replace(/"/g, '\\"') + '"' | ||
return '"' + value.toString().replace(/"/g, '\\"') + '"' | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2342
90500
7
219
1
+ Addedbluebird@^2.9.34
+ Addedasync@2.6.4(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addedform-data@1.0.1(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
- Removedasync@^0.9.0
- Removedasync@0.9.2(transitive)
- Removedcombined-stream@0.0.7(transitive)
- Removeddelayed-stream@0.0.5(transitive)
- Removedform-data@0.2.0(transitive)
- Removedmime-db@1.12.0(transitive)
- Removedmime-types@2.0.14(transitive)
Updatedchalk@^1.1.0
Updatedcommander@^2.8.1
Updateddebug@^2.2.0
Updatedevent-stream@^3.3.1
Updatedform-data@^1.0.0-rc3
Updatedhar-validator@^1.8.0
Updatedrequire-directory@^2.1.1