"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "helpers/codegen/generators/python-requests.js" between
hoppscotch-2.0.0.tar.gz and hoppscotch-2.1.0.tar.gz

About: Hoppscotch is a light-weight, web based API development suite.

python-requests.js  (hoppscotch-2.0.0):python-requests.js  (hoppscotch-2.1.0)
skipping to change at line 34 skipping to change at line 34
rawInput, rawInput,
rawParams, rawParams,
rawRequestBody, rawRequestBody,
contentType, contentType,
headers, headers,
}) => { }) => {
const requestString = [] const requestString = []
const genHeaders = [] const genHeaders = []
requestString.push(`import requests\n\n`) requestString.push(`import requests\n\n`)
requestString.push(`url = '${url}${pathName}${queryString}'\n`) requestString.push(`url = '${url}${pathName}?${queryString}'\n`)
// auth headers // auth headers
if (auth === "Basic Auth") { if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}` const basic = `${httpUser}:${httpPassword}`
genHeaders.push( genHeaders.push(
`'Authorization': 'Basic ${window.btoa( `'Authorization': 'Basic ${window.btoa(
unescape(encodeURIComponent(basic)) unescape(encodeURIComponent(basic))
)}'` )}'`
) )
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") { } else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
skipping to change at line 61 skipping to change at line 61
if (key) genHeaders.push(`'${key}': '${value}'`) if (key) genHeaders.push(`'${key}': '${value}'`)
}) })
} }
// initial request setup // initial request setup
let requestBody = rawInput ? rawParams : rawRequestBody let requestBody = rawInput ? rawParams : rawRequestBody
if (method === "GET") { if (method === "GET") {
requestString.push(...printHeaders(genHeaders)) requestString.push(...printHeaders(genHeaders))
requestString.push(`response = requests.request(\n`) requestString.push(`response = requests.request(\n`)
requestString.push(` '${method}',\n`) requestString.push(` '${method}',\n`)
requestString.push(` '${url}${pathName}${queryString}',\n`) requestString.push(` '${url}${pathName}?${queryString}',\n`)
} }
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) { if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
genHeaders.push(`'Content-Type': '${contentType}'`) genHeaders.push(`'Content-Type': '${contentType}'`)
requestString.push(...printHeaders(genHeaders)) requestString.push(...printHeaders(genHeaders))
if (isJSONContentType(contentType)) { if (isJSONContentType(contentType)) {
requestBody = JSON.stringify(requestBody) requestBody = JSON.stringify(requestBody)
requestString.push(`data = ${requestBody}\n`) requestString.push(`data = ${requestBody}\n`)
} else if (contentType.includes("x-www-form-urlencoded")) { } else if (contentType.includes("x-www-form-urlencoded")) {
const formData = [] const formData = []
skipping to change at line 86 skipping to change at line 86
}) })
} }
if (formData.length) { if (formData.length) {
requestString.push(`data = [${formData.join(",\n ")}]\n`) requestString.push(`data = [${formData.join(",\n ")}]\n`)
} }
} else { } else {
requestString.push(`data = '''${requestBody}'''\n`) requestString.push(`data = '''${requestBody}'''\n`)
} }
requestString.push(`response = requests.request(\n`) requestString.push(`response = requests.request(\n`)
requestString.push(` '${method}',\n`) requestString.push(` '${method}',\n`)
requestString.push(` '${url}${pathName}${queryString}',\n`) requestString.push(` '${url}${pathName}?${queryString}',\n`)
requestString.push(` data=data,\n`) requestString.push(` data=data,\n`)
} }
if (genHeaders.length) { if (genHeaders.length) {
requestString.push(` headers=headers,\n`) requestString.push(` headers=headers,\n`)
} }
requestString.push(`)\n\n`) requestString.push(`)\n\n`)
requestString.push(`print(response)`) requestString.push(`print(response)`)
 End of changes. 3 change blocks. 
3 lines changed or deleted 3 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)