@readme/httpsnippet 3.1.3 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/README.md +63 -62
  2. package/dist/package.json +86 -0
  3. package/dist/src/fixtures/customTarget.js +15 -0
  4. package/dist/src/fixtures/mimetypes.js +77 -0
  5. package/dist/src/fixtures/requests/application-form-encoded.js +69 -0
  6. package/dist/src/fixtures/requests/application-json.js +72 -0
  7. package/dist/src/fixtures/requests/cookies.js +51 -0
  8. package/dist/src/fixtures/requests/custom-method.js +41 -0
  9. package/dist/src/fixtures/requests/full.js +99 -0
  10. package/dist/src/fixtures/requests/headers.js +56 -0
  11. package/dist/src/fixtures/requests/http-insecure.js +45 -0
  12. package/dist/src/fixtures/requests/jsonObj-multiline.js +59 -0
  13. package/dist/src/fixtures/requests/jsonObj-null-value.js +61 -0
  14. package/dist/src/fixtures/requests/multipart-data.js +72 -0
  15. package/dist/src/fixtures/requests/multipart-file.js +65 -0
  16. package/dist/src/fixtures/requests/multipart-form-data-no-params.js +56 -0
  17. package/dist/src/fixtures/requests/multipart-form-data.js +64 -0
  18. package/dist/src/fixtures/requests/nested.js +64 -0
  19. package/dist/src/fixtures/requests/query-encoded.js +59 -0
  20. package/dist/src/fixtures/requests/query.js +64 -0
  21. package/dist/src/fixtures/requests/short.js +45 -0
  22. package/dist/src/fixtures/requests/text-plain.js +57 -0
  23. package/dist/src/fixtures/runCustomFixtures.js +77 -0
  24. package/dist/src/helpers/code-builder.js +91 -0
  25. package/dist/src/helpers/form-data.js +157 -0
  26. package/dist/src/helpers/har-validator.js +76 -0
  27. package/dist/src/helpers/headers.js +33 -0
  28. package/dist/src/helpers/reducer.js +19 -0
  29. package/dist/src/helpers/shell.js +20 -0
  30. package/dist/src/helpers/utils.js +21 -0
  31. package/dist/src/index.js +285 -0
  32. package/dist/src/targets/c/libcurl/client.js +43 -0
  33. package/dist/src/targets/c/target.js +15 -0
  34. package/dist/src/targets/clojure/clj_http/client.js +184 -0
  35. package/dist/src/targets/clojure/target.js +15 -0
  36. package/dist/src/targets/csharp/httpclient/client.js +162 -0
  37. package/dist/src/targets/csharp/restsharp/client.js +38 -0
  38. package/dist/src/targets/csharp/target.js +17 -0
  39. package/dist/src/targets/go/native/client.js +122 -0
  40. package/dist/src/targets/go/target.js +15 -0
  41. package/dist/src/targets/http/http1.1/client.js +79 -0
  42. package/dist/src/targets/http/target.js +15 -0
  43. package/dist/src/targets/java/asynchttp/client.js +53 -0
  44. package/dist/src/targets/java/nethttp/client.js +52 -0
  45. package/dist/src/targets/java/okhttp/client.js +79 -0
  46. package/dist/src/targets/java/target.js +21 -0
  47. package/dist/src/targets/java/unirest/client.js +53 -0
  48. package/dist/src/targets/javascript/axios/client.js +101 -0
  49. package/dist/src/targets/javascript/axios/fixtures/application-form-encoded.js +22 -0
  50. package/dist/src/targets/javascript/axios/fixtures/application-json.js +26 -0
  51. package/dist/src/targets/javascript/axios/fixtures/cookies.js +18 -0
  52. package/dist/src/targets/javascript/axios/fixtures/custom-method.js +14 -0
  53. package/dist/src/targets/javascript/axios/fixtures/full.js +26 -0
  54. package/dist/src/targets/javascript/axios/fixtures/headers.js +18 -0
  55. package/dist/src/targets/javascript/axios/fixtures/http-insecure.js +14 -0
  56. package/dist/src/targets/javascript/axios/fixtures/jsonObj-multiline.js +19 -0
  57. package/dist/src/targets/javascript/axios/fixtures/jsonObj-null-value.js +19 -0
  58. package/dist/src/targets/javascript/axios/fixtures/multipart-data.js +22 -0
  59. package/dist/src/targets/javascript/axios/fixtures/multipart-file.js +21 -0
  60. package/dist/src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js +18 -0
  61. package/dist/src/targets/javascript/axios/fixtures/multipart-form-data.js +21 -0
  62. package/dist/src/targets/javascript/axios/fixtures/nested.js +18 -0
  63. package/dist/src/targets/javascript/axios/fixtures/query-encoded.js +21 -0
  64. package/dist/src/targets/javascript/axios/fixtures/query.js +18 -0
  65. package/dist/src/targets/javascript/axios/fixtures/short.js +14 -0
  66. package/dist/src/targets/javascript/axios/fixtures/text-plain.js +19 -0
  67. package/dist/src/targets/javascript/fetch/client.js +115 -0
  68. package/dist/src/targets/javascript/fetch/fixtures/application-form-encoded.js +9 -0
  69. package/dist/src/targets/javascript/fetch/fixtures/application-json.js +16 -0
  70. package/dist/src/targets/javascript/fetch/fixtures/cookies.js +5 -0
  71. package/dist/src/targets/javascript/fetch/fixtures/custom-method.js +5 -0
  72. package/dist/src/targets/javascript/fetch/fixtures/full.js +13 -0
  73. package/dist/src/targets/javascript/fetch/fixtures/headers.js +8 -0
  74. package/dist/src/targets/javascript/fetch/fixtures/http-insecure.js +5 -0
  75. package/dist/src/targets/javascript/fetch/fixtures/jsonObj-multiline.js +9 -0
  76. package/dist/src/targets/javascript/fetch/fixtures/jsonObj-null-value.js +9 -0
  77. package/dist/src/targets/javascript/fetch/fixtures/multipart-data.js +9 -0
  78. package/dist/src/targets/javascript/fetch/fixtures/multipart-file.js +8 -0
  79. package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data-no-params.js +5 -0
  80. package/dist/src/targets/javascript/fetch/fixtures/multipart-form-data.js +8 -0
  81. package/dist/src/targets/javascript/fetch/fixtures/nested.js +5 -0
  82. package/dist/src/targets/javascript/fetch/fixtures/query-encoded.js +5 -0
  83. package/dist/src/targets/javascript/fetch/fixtures/query.js +5 -0
  84. package/dist/src/targets/javascript/fetch/fixtures/short.js +5 -0
  85. package/dist/src/targets/javascript/fetch/fixtures/text-plain.js +5 -0
  86. package/dist/src/targets/javascript/jquery/client.js +93 -0
  87. package/dist/src/targets/javascript/jquery/fixtures/application-form-encoded.js +17 -0
  88. package/dist/src/targets/javascript/jquery/fixtures/application-json.js +15 -0
  89. package/dist/src/targets/javascript/jquery/fixtures/cookies.js +13 -0
  90. package/dist/src/targets/javascript/jquery/fixtures/custom-method.js +11 -0
  91. package/dist/src/targets/javascript/jquery/fixtures/full.js +18 -0
  92. package/dist/src/targets/javascript/jquery/fixtures/headers.js +15 -0
  93. package/dist/src/targets/javascript/jquery/fixtures/http-insecure.js +11 -0
  94. package/dist/src/targets/javascript/jquery/fixtures/jsonObj-multiline.js +15 -0
  95. package/dist/src/targets/javascript/jquery/fixtures/jsonObj-null-value.js +15 -0
  96. package/dist/src/targets/javascript/jquery/fixtures/multipart-data.js +18 -0
  97. package/dist/src/targets/javascript/jquery/fixtures/multipart-file.js +17 -0
  98. package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data-no-params.js +13 -0
  99. package/dist/src/targets/javascript/jquery/fixtures/multipart-form-data.js +17 -0
  100. package/dist/src/targets/javascript/jquery/fixtures/nested.js +11 -0
  101. package/dist/src/targets/javascript/jquery/fixtures/query-encoded.js +11 -0
  102. package/dist/src/targets/javascript/jquery/fixtures/query.js +11 -0
  103. package/dist/src/targets/javascript/jquery/fixtures/short.js +11 -0
  104. package/dist/src/targets/javascript/jquery/fixtures/text-plain.js +14 -0
  105. package/dist/src/targets/javascript/target.js +21 -0
  106. package/dist/src/targets/javascript/xhr/client.js +90 -0
  107. package/dist/src/targets/javascript/xhr/fixtures/application-form-encoded.js +12 -0
  108. package/dist/src/targets/javascript/xhr/fixtures/application-json.js +31 -0
  109. package/dist/src/targets/javascript/xhr/fixtures/cookies.js +12 -0
  110. package/dist/src/targets/javascript/xhr/fixtures/cors.js +10 -0
  111. package/dist/src/targets/javascript/xhr/fixtures/custom-method.js +11 -0
  112. package/dist/src/targets/javascript/xhr/fixtures/full.js +14 -0
  113. package/dist/src/targets/javascript/xhr/fixtures/headers.js +14 -0
  114. package/dist/src/targets/javascript/xhr/fixtures/http-insecure.js +11 -0
  115. package/dist/src/targets/javascript/xhr/fixtures/jsonObj-multiline.js +14 -0
  116. package/dist/src/targets/javascript/xhr/fixtures/jsonObj-null-value.js +14 -0
  117. package/dist/src/targets/javascript/xhr/fixtures/multipart-data.js +13 -0
  118. package/dist/src/targets/javascript/xhr/fixtures/multipart-file.js +12 -0
  119. package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data-no-params.js +11 -0
  120. package/dist/src/targets/javascript/xhr/fixtures/multipart-form-data.js +12 -0
  121. package/dist/src/targets/javascript/xhr/fixtures/nested.js +11 -0
  122. package/dist/src/targets/javascript/xhr/fixtures/query-encoded.js +11 -0
  123. package/dist/src/targets/javascript/xhr/fixtures/query.js +11 -0
  124. package/dist/src/targets/javascript/xhr/fixtures/short.js +11 -0
  125. package/dist/src/targets/javascript/xhr/fixtures/text-plain.js +12 -0
  126. package/dist/src/targets/kotlin/okhttp/client.js +79 -0
  127. package/dist/src/targets/kotlin/target.js +15 -0
  128. package/dist/src/targets/node/axios/client.js +87 -0
  129. package/dist/src/targets/node/axios/fixtures/application-form-encoded.js +19 -0
  130. package/dist/src/targets/node/axios/fixtures/application-json.js +22 -0
  131. package/dist/src/targets/node/axios/fixtures/cookies.js +14 -0
  132. package/dist/src/targets/node/axios/fixtures/custom-method.js +10 -0
  133. package/dist/src/targets/node/axios/fixtures/full.js +22 -0
  134. package/dist/src/targets/node/axios/fixtures/headers.js +14 -0
  135. package/dist/src/targets/node/axios/fixtures/http-insecure.js +10 -0
  136. package/dist/src/targets/node/axios/fixtures/jsonObj-multiline.js +15 -0
  137. package/dist/src/targets/node/axios/fixtures/jsonObj-null-value.js +15 -0
  138. package/dist/src/targets/node/axios/fixtures/multipart-data.js +15 -0
  139. package/dist/src/targets/node/axios/fixtures/multipart-file.js +15 -0
  140. package/dist/src/targets/node/axios/fixtures/multipart-form-data-no-params.js +14 -0
  141. package/dist/src/targets/node/axios/fixtures/multipart-form-data.js +15 -0
  142. package/dist/src/targets/node/axios/fixtures/nested.js +13 -0
  143. package/dist/src/targets/node/axios/fixtures/query-encoded.js +13 -0
  144. package/dist/src/targets/node/axios/fixtures/query.js +13 -0
  145. package/dist/src/targets/node/axios/fixtures/short.js +10 -0
  146. package/dist/src/targets/node/axios/fixtures/text-plain.js +15 -0
  147. package/dist/src/targets/node/fetch/client.js +149 -0
  148. package/dist/src/targets/node/fetch/fixtures/application-form-encoded.js +15 -0
  149. package/dist/src/targets/node/fetch/fixtures/application-json.js +18 -0
  150. package/dist/src/targets/node/fetch/fixtures/cookies.js +7 -0
  151. package/dist/src/targets/node/fetch/fixtures/custom-method.js +7 -0
  152. package/dist/src/targets/node/fetch/fixtures/full.js +18 -0
  153. package/dist/src/targets/node/fetch/fixtures/headers.js +10 -0
  154. package/dist/src/targets/node/fetch/fixtures/http-insecure.js +7 -0
  155. package/dist/src/targets/node/fetch/fixtures/jsonObj-multiline.js +11 -0
  156. package/dist/src/targets/node/fetch/fixtures/jsonObj-null-value.js +11 -0
  157. package/dist/src/targets/node/fetch/fixtures/multipart-data.js +13 -0
  158. package/dist/src/targets/node/fetch/fixtures/multipart-file.js +12 -0
  159. package/dist/src/targets/node/fetch/fixtures/multipart-form-data-no-params.js +7 -0
  160. package/dist/src/targets/node/fetch/fixtures/multipart-form-data.js +11 -0
  161. package/dist/src/targets/node/fetch/fixtures/nested.js +7 -0
  162. package/dist/src/targets/node/fetch/fixtures/query-encoded.js +7 -0
  163. package/dist/src/targets/node/fetch/fixtures/query.js +7 -0
  164. package/dist/src/targets/node/fetch/fixtures/short.js +7 -0
  165. package/dist/src/targets/node/fetch/fixtures/text-plain.js +7 -0
  166. package/dist/src/targets/node/native/client.js +91 -0
  167. package/dist/src/targets/node/native/fixtures/application-form-encoded.js +24 -0
  168. package/dist/src/targets/node/native/fixtures/application-json.js +30 -0
  169. package/dist/src/targets/node/native/fixtures/cookies.js +22 -0
  170. package/dist/src/targets/node/native/fixtures/custom-method.js +20 -0
  171. package/dist/src/targets/node/native/fixtures/full.js +26 -0
  172. package/dist/src/targets/node/native/fixtures/headers.js +24 -0
  173. package/dist/src/targets/node/native/fixtures/http-insecure.js +20 -0
  174. package/dist/src/targets/node/native/fixtures/jsonObj-multiline.js +23 -0
  175. package/dist/src/targets/node/native/fixtures/jsonObj-null-value.js +23 -0
  176. package/dist/src/targets/node/native/fixtures/multipart-data.js +23 -0
  177. package/dist/src/targets/node/native/fixtures/multipart-file.js +23 -0
  178. package/dist/src/targets/node/native/fixtures/multipart-form-data-no-params.js +22 -0
  179. package/dist/src/targets/node/native/fixtures/multipart-form-data.js +23 -0
  180. package/dist/src/targets/node/native/fixtures/nested.js +20 -0
  181. package/dist/src/targets/node/native/fixtures/query-encoded.js +20 -0
  182. package/dist/src/targets/node/native/fixtures/query.js +20 -0
  183. package/dist/src/targets/node/native/fixtures/short.js +20 -0
  184. package/dist/src/targets/node/native/fixtures/text-plain.js +23 -0
  185. package/dist/src/targets/node/request/client.js +116 -0
  186. package/dist/src/targets/node/request/fixtures/application-form-encoded.js +13 -0
  187. package/dist/src/targets/node/request/fixtures/application-json.js +21 -0
  188. package/dist/src/targets/node/request/fixtures/cookies.js +11 -0
  189. package/dist/src/targets/node/request/fixtures/custom-method.js +8 -0
  190. package/dist/src/targets/node/request/fixtures/full.js +20 -0
  191. package/dist/src/targets/node/request/fixtures/headers.js +12 -0
  192. package/dist/src/targets/node/request/fixtures/http-insecure.js +8 -0
  193. package/dist/src/targets/node/request/fixtures/jsonObj-multiline.js +14 -0
  194. package/dist/src/targets/node/request/fixtures/jsonObj-null-value.js +14 -0
  195. package/dist/src/targets/node/request/fixtures/multipart-data.js +20 -0
  196. package/dist/src/targets/node/request/fixtures/multipart-file.js +19 -0
  197. package/dist/src/targets/node/request/fixtures/multipart-form-data-no-params.js +12 -0
  198. package/dist/src/targets/node/request/fixtures/multipart-form-data.js +13 -0
  199. package/dist/src/targets/node/request/fixtures/nested.js +11 -0
  200. package/dist/src/targets/node/request/fixtures/query-encoded.js +11 -0
  201. package/dist/src/targets/node/request/fixtures/query.js +11 -0
  202. package/dist/src/targets/node/request/fixtures/short.js +8 -0
  203. package/dist/src/targets/node/request/fixtures/text-plain.js +13 -0
  204. package/dist/src/targets/node/target.js +24 -0
  205. package/dist/src/targets/node/unirest/client.js +119 -0
  206. package/dist/src/targets/node/unirest/fixtures/application-form-encoded.js +15 -0
  207. package/dist/src/targets/node/unirest/fixtures/application-json.js +32 -0
  208. package/dist/src/targets/node/unirest/fixtures/cookies.js +12 -0
  209. package/dist/src/targets/node/unirest/fixtures/custom-method.js +8 -0
  210. package/dist/src/targets/node/unirest/fixtures/full.js +27 -0
  211. package/dist/src/targets/node/unirest/fixtures/headers.js +13 -0
  212. package/dist/src/targets/node/unirest/fixtures/http-insecure.js +8 -0
  213. package/dist/src/targets/node/unirest/fixtures/jsonObj-multiline.js +15 -0
  214. package/dist/src/targets/node/unirest/fixtures/jsonObj-null-value.js +15 -0
  215. package/dist/src/targets/node/unirest/fixtures/multipart-data.js +20 -0
  216. package/dist/src/targets/node/unirest/fixtures/multipart-file.js +18 -0
  217. package/dist/src/targets/node/unirest/fixtures/multipart-form-data-no-params.js +11 -0
  218. package/dist/src/targets/node/unirest/fixtures/multipart-form-data.js +16 -0
  219. package/dist/src/targets/node/unirest/fixtures/nested.js +13 -0
  220. package/dist/src/targets/node/unirest/fixtures/query-encoded.js +12 -0
  221. package/dist/src/targets/node/unirest/fixtures/query.js +16 -0
  222. package/dist/src/targets/node/unirest/fixtures/short.js +8 -0
  223. package/dist/src/targets/node/unirest/fixtures/text-plain.js +12 -0
  224. package/dist/src/targets/objc/helpers.js +59 -0
  225. package/dist/src/targets/objc/nsurlsession/client.js +151 -0
  226. package/dist/src/targets/objc/target.js +15 -0
  227. package/dist/src/targets/ocaml/cohttp/client.js +72 -0
  228. package/dist/src/targets/ocaml/target.js +15 -0
  229. package/dist/src/targets/php/curl/client.js +135 -0
  230. package/dist/src/targets/php/guzzle/client.js +126 -0
  231. package/dist/src/targets/php/helpers.js +63 -0
  232. package/dist/src/targets/php/http1/client.js +90 -0
  233. package/dist/src/targets/php/http2/client.js +128 -0
  234. package/dist/src/targets/php/target.js +22 -0
  235. package/dist/src/targets/powershell/common.js +49 -0
  236. package/dist/src/targets/powershell/restmethod/client.js +13 -0
  237. package/dist/src/targets/powershell/target.js +17 -0
  238. package/dist/src/targets/powershell/webrequest/client.js +13 -0
  239. package/dist/src/targets/python/helpers.js +70 -0
  240. package/dist/src/targets/python/requests/client.js +161 -0
  241. package/dist/src/targets/python/target.js +16 -0
  242. package/dist/src/targets/r/httr/client.js +125 -0
  243. package/dist/src/targets/r/target.js +15 -0
  244. package/dist/src/targets/ruby/native/client.js +69 -0
  245. package/dist/src/targets/ruby/target.js +15 -0
  246. package/dist/src/targets/shell/curl/client.js +171 -0
  247. package/dist/src/targets/shell/httpie/client.js +111 -0
  248. package/dist/src/targets/shell/target.js +20 -0
  249. package/dist/src/targets/shell/wget/client.js +55 -0
  250. package/dist/src/targets/swift/helpers.js +80 -0
  251. package/dist/src/targets/swift/nsurlsession/client.js +156 -0
  252. package/dist/src/targets/swift/target.js +15 -0
  253. package/dist/src/targets/targets.js +130 -0
  254. package/package.json +26 -21
  255. package/src/helpers/code-builder.js +0 -108
  256. package/src/helpers/form-data.js +0 -107
  257. package/src/helpers/headers.js +0 -48
  258. package/src/helpers/reducer.js +0 -20
  259. package/src/index.js +0 -361
  260. package/src/targets/c/index.js +0 -10
  261. package/src/targets/c/libcurl.js +0 -45
  262. package/src/targets/clojure/clj_http.js +0 -176
  263. package/src/targets/clojure/index.js +0 -10
  264. package/src/targets/csharp/httpclient.js +0 -157
  265. package/src/targets/csharp/index.js +0 -11
  266. package/src/targets/csharp/restsharp.js +0 -49
  267. package/src/targets/go/index.js +0 -10
  268. package/src/targets/go/native.js +0 -130
  269. package/src/targets/http/http1.1.js +0 -89
  270. package/src/targets/http/index.js +0 -10
  271. package/src/targets/index.js +0 -20
  272. package/src/targets/java/asynchttp.js +0 -54
  273. package/src/targets/java/index.js +0 -13
  274. package/src/targets/java/nethttp.js +0 -59
  275. package/src/targets/java/okhttp.js +0 -78
  276. package/src/targets/java/unirest.js +0 -57
  277. package/src/targets/javascript/axios.js +0 -101
  278. package/src/targets/javascript/fetch.js +0 -129
  279. package/src/targets/javascript/index.js +0 -13
  280. package/src/targets/javascript/jquery.js +0 -89
  281. package/src/targets/javascript/xhr.js +0 -86
  282. package/src/targets/kotlin/index.js +0 -10
  283. package/src/targets/kotlin/okhttp.js +0 -78
  284. package/src/targets/node/axios.js +0 -76
  285. package/src/targets/node/fetch.js +0 -145
  286. package/src/targets/node/index.js +0 -15
  287. package/src/targets/node/native.js +0 -92
  288. package/src/targets/node/request.js +0 -126
  289. package/src/targets/node/unirest.js +0 -120
  290. package/src/targets/objc/helpers.js +0 -80
  291. package/src/targets/objc/index.js +0 -10
  292. package/src/targets/objc/nsurlsession.js +0 -164
  293. package/src/targets/ocaml/cohttp.js +0 -73
  294. package/src/targets/ocaml/index.js +0 -10
  295. package/src/targets/php/curl.js +0 -142
  296. package/src/targets/php/guzzle.js +0 -135
  297. package/src/targets/php/helpers.js +0 -87
  298. package/src/targets/php/http1.js +0 -85
  299. package/src/targets/php/http2.js +0 -131
  300. package/src/targets/php/index.js +0 -14
  301. package/src/targets/powershell/common.js +0 -60
  302. package/src/targets/powershell/index.js +0 -11
  303. package/src/targets/powershell/restmethod.js +0 -8
  304. package/src/targets/powershell/webrequest.js +0 -8
  305. package/src/targets/python/helpers.js +0 -85
  306. package/src/targets/python/index.js +0 -11
  307. package/src/targets/python/requests.js +0 -163
  308. package/src/targets/r/httr.js +0 -134
  309. package/src/targets/r/index.js +0 -10
  310. package/src/targets/ruby/index.js +0 -10
  311. package/src/targets/ruby/native.js +0 -71
  312. package/src/targets/shell/curl.js +0 -157
  313. package/src/targets/shell/helpers.js +0 -23
  314. package/src/targets/shell/httpie.js +0 -129
  315. package/src/targets/shell/index.js +0 -13
  316. package/src/targets/shell/wget.js +0 -52
  317. package/src/targets/swift/helpers.js +0 -93
  318. package/src/targets/swift/index.js +0 -10
  319. package/src/targets/swift/nsurlsession.js +0 -152
@@ -1,131 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for PHP using curl-ext.
4
- *
5
- * @author
6
- * @AhmadNassri
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
-
11
- const helpers = require('./helpers');
12
- const headerHelpers = require('../../helpers/headers');
13
- const CodeBuilder = require('../../helpers/code-builder');
14
-
15
- module.exports = function (source, options) {
16
- const opts = {
17
- closingTag: false,
18
- indent: ' ',
19
- noTags: false,
20
- shortTags: false,
21
- ...options,
22
- };
23
-
24
- const code = new CodeBuilder(opts.indent);
25
- let hasBody = false;
26
-
27
- if (!opts.noTags) {
28
- code.push(opts.shortTags ? '<?' : '<?php').blank();
29
- }
30
-
31
- code.push('$client = new http\\Client;').push('$request = new http\\Client\\Request;').blank();
32
-
33
- switch (source.postData.mimeType) {
34
- case 'application/x-www-form-urlencoded':
35
- code
36
- .push('$body = new http\\Message\\Body;')
37
- .push('$body->append(new http\\QueryString(%s));', helpers.convert(source.postData.paramsObj, opts.indent))
38
- .blank();
39
- hasBody = true;
40
- break;
41
-
42
- case 'multipart/form-data': {
43
- if (source.postData.params) {
44
- const files = [];
45
- const fields = {};
46
-
47
- source.postData.params.forEach(function (param) {
48
- if (param.fileName) {
49
- files.push({
50
- name: param.name,
51
- type: param.contentType,
52
- file: param.fileName,
53
- data: param.value,
54
- });
55
- } else if (param.value) {
56
- fields[param.name] = param.value;
57
- }
58
- });
59
-
60
- code
61
- .push('$body = new http\\Message\\Body;')
62
- .push(
63
- '$body->addForm(%s, %s);',
64
- Object.keys(fields).length ? helpers.convert(fields, opts.indent) : 'null',
65
- files.length ? helpers.convert(files, opts.indent) : 'null'
66
- );
67
-
68
- // remove the contentType header
69
- if (headerHelpers.hasHeader(source.headersObj, 'content-type')) {
70
- if (headerHelpers.getHeader(source.headersObj, 'content-type').includes('boundary')) {
71
- // eslint-disable-next-line no-param-reassign
72
- delete source.headersObj[headerHelpers.getHeaderName(source.headersObj, 'content-type')];
73
- }
74
- }
75
-
76
- code.blank();
77
-
78
- hasBody = true;
79
- }
80
- break;
81
- }
82
-
83
- default:
84
- if (source.postData.text) {
85
- code
86
- .push('$body = new http\\Message\\Body;')
87
- .push('$body->append(%s);', helpers.convert(source.postData.text))
88
- .blank();
89
- hasBody = true;
90
- }
91
- }
92
-
93
- code
94
- .push('$request->setRequestUrl(%s);', helpers.convert(source.url))
95
- .push('$request->setRequestMethod(%s);', helpers.convert(source.method));
96
-
97
- if (hasBody) {
98
- code.push('$request->setBody($body);').blank();
99
- }
100
-
101
- if (Object.keys(source.queryObj).length) {
102
- code.push('$request->setQuery(new http\\QueryString(%s));', helpers.convert(source.queryObj, opts.indent)).blank();
103
- }
104
-
105
- if (Object.keys(source.headersObj).length) {
106
- code.push('$request->setHeaders(%s);', helpers.convert(source.headersObj, opts.indent)).blank();
107
- }
108
-
109
- if (Object.keys(source.cookiesObj).length) {
110
- code.blank().push('$client->setCookies(%s);', helpers.convert(source.cookiesObj, opts.indent)).blank();
111
- }
112
-
113
- code
114
- .push('$client->enqueue($request)->send();')
115
- .push('$response = $client->getResponse();')
116
- .blank()
117
- .push('echo $response->getBody();');
118
-
119
- if (!opts.noTags && opts.closingTag) {
120
- code.blank().push('?>');
121
- }
122
-
123
- return code.join();
124
- };
125
-
126
- module.exports.info = {
127
- key: 'http2',
128
- title: 'HTTP v2',
129
- link: 'http://devel-m6w6.rhcloud.com/mdref/http',
130
- description: 'PHP with pecl/http v2',
131
- };
@@ -1,14 +0,0 @@
1
- module.exports = {
2
- info: {
3
- key: 'php',
4
- title: 'PHP',
5
- extname: '.php',
6
- default: 'curl',
7
- cli: 'php %s',
8
- },
9
-
10
- curl: require('./curl'),
11
- http1: require('./http1'),
12
- http2: require('./http2'),
13
- guzzle: require('./guzzle'),
14
- };
@@ -1,60 +0,0 @@
1
- const CodeBuilder = require('../../helpers/code-builder');
2
- const helpers = require('../../helpers/headers');
3
-
4
- module.exports = function (command) {
5
- return function (source) {
6
- const code = new CodeBuilder();
7
- const methods = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
8
-
9
- if (!methods.includes(source.method.toUpperCase())) {
10
- return 'Method not supported';
11
- }
12
-
13
- const commandOptions = [];
14
-
15
- // Add headers, including the cookies
16
- const headers = Object.keys(source.headersObj);
17
-
18
- // construct headers
19
- if (headers.length) {
20
- code.push('$headers=@{}');
21
- headers.forEach(function (key) {
22
- if (key !== 'connection') {
23
- // Not allowed
24
- code.push('$headers.Add("%s", "%s")', key, source.headersObj[key]);
25
- }
26
- });
27
- commandOptions.push('-Headers $headers');
28
- }
29
-
30
- // construct cookies
31
- if (source.cookies.length) {
32
- code.push('$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession');
33
-
34
- source.cookies.forEach(function (cookie) {
35
- code.push('$cookie = New-Object System.Net.Cookie');
36
-
37
- code.push("$cookie.Name = '%s'", cookie.name);
38
- code.push("$cookie.Value = '%s'", cookie.value);
39
- code.push("$cookie.Domain = '%s'", source.uriObj.host);
40
-
41
- code.push('$session.Cookies.Add($cookie)');
42
- });
43
- commandOptions.push('-WebSession $session');
44
- }
45
-
46
- if (source.postData.text) {
47
- commandOptions.push(`-ContentType '${helpers.getHeader(source.allHeaders, 'content-type')}'`);
48
- commandOptions.push(`-Body '${source.postData.text}'`);
49
- }
50
-
51
- code.push(
52
- "$response = %s -Uri '%s' -Method %s %s",
53
- command,
54
- source.fullUrl,
55
- source.method,
56
- commandOptions.join(' ')
57
- );
58
- return code.join();
59
- };
60
- };
@@ -1,11 +0,0 @@
1
- module.exports = {
2
- info: {
3
- key: 'powershell',
4
- title: 'Powershell',
5
- extname: '.ps1',
6
- default: 'webrequest',
7
- },
8
-
9
- webrequest: require('./webrequest'),
10
- restmethod: require('./restmethod'),
11
- };
@@ -1,8 +0,0 @@
1
- module.exports = require('./common')('Invoke-RestMethod');
2
-
3
- module.exports.info = {
4
- key: 'restmethod',
5
- title: 'Invoke-RestMethod',
6
- link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-RestMethod',
7
- description: 'Powershell Invoke-RestMethod client',
8
- };
@@ -1,8 +0,0 @@
1
- module.exports = require('./common')('Invoke-WebRequest');
2
-
3
- module.exports.info = {
4
- key: 'webrequest',
5
- title: 'Invoke-WebRequest',
6
- link: 'https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Utility/Invoke-WebRequest',
7
- description: 'Powershell Invoke-WebRequest client',
8
- };
@@ -1,85 +0,0 @@
1
- const { format } = require('util');
2
-
3
- /**
4
- * Create an string of given length filled with blank spaces
5
- *
6
- * @param {number} length Length of the array to return
7
- * @param {string} str String to pad out with
8
- * @return {string}
9
- */
10
- function buildString(length, str) {
11
- // eslint-disable-next-line prefer-spread
12
- return Array.apply(null, new Array(length)).map(String.prototype.valueOf, str).join('');
13
- }
14
-
15
- /**
16
- * Create a string corresponding to a Dictionary or Array literal representation with pretty option
17
- * and indentation.
18
- */
19
- function concatValues(concatType, values, pretty, indentation, indentLevel) {
20
- const currentIndent = buildString(indentLevel, indentation);
21
- const closingBraceIndent = buildString(indentLevel - 1, indentation);
22
- const join = pretty ? `,\n${currentIndent}` : ', ';
23
- const openingBrace = concatType === 'object' ? '{' : '[';
24
- const closingBrace = concatType === 'object' ? '}' : ']';
25
-
26
- if (pretty) {
27
- return `${openingBrace}\n${currentIndent}${values.join(join)}\n${closingBraceIndent}${closingBrace}`;
28
- }
29
-
30
- return openingBrace + values.join(join) + closingBrace;
31
- }
32
-
33
- module.exports = {
34
- /**
35
- * Create a valid Python string of a literal value according to its type.
36
- *
37
- * @param {*} value Any JavaScript literal
38
- * @param {Object} opts Target options
39
- * @return {string}
40
- */
41
- literalRepresentation: function (value, opts, indentLevel) {
42
- // eslint-disable-next-line no-param-reassign
43
- indentLevel = indentLevel === undefined ? 1 : indentLevel + 1;
44
-
45
- switch (Object.prototype.toString.call(value)) {
46
- case '[object Number]':
47
- return value;
48
-
49
- case '[object Array]': {
50
- let pretty = false;
51
- const valuesRepresentation = value.map(
52
- function (v) {
53
- // Switch to prettify if the value is a dictionary with multiple keys
54
- if (Object.prototype.toString.call(v) === '[object Object]') {
55
- pretty = Object.keys(v).length > 1;
56
- }
57
- return this.literalRepresentation(v, opts, indentLevel);
58
- }.bind(this)
59
- );
60
- return concatValues('array', valuesRepresentation, pretty, opts.indent, indentLevel);
61
- }
62
-
63
- case '[object Object]': {
64
- const keyValuePairs = [];
65
- // eslint-disable-next-line guard-for-in, no-restricted-syntax
66
- for (const k in value) {
67
- keyValuePairs.push(format('"%s": %s', k, this.literalRepresentation(value[k], opts, indentLevel)));
68
- }
69
- return concatValues('object', keyValuePairs, opts.pretty && keyValuePairs.length > 1, opts.indent, indentLevel);
70
- }
71
-
72
- case '[object Null]':
73
- return 'None';
74
-
75
- case '[object Boolean]':
76
- return value ? 'True' : 'False';
77
-
78
- default:
79
- if (value === null || value === undefined) {
80
- return '';
81
- }
82
- return `"${value.toString().replace(/"/g, '\\"')}"`;
83
- }
84
- },
85
- };
@@ -1,11 +0,0 @@
1
- module.exports = {
2
- info: {
3
- key: 'python',
4
- title: 'Python',
5
- extname: '.py',
6
- default: 'requests',
7
- cli: 'python3 %s',
8
- },
9
-
10
- requests: require('./requests'),
11
- };
@@ -1,163 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for Python using Requests
4
- *
5
- * @author
6
- * @montanaflynn
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
-
11
- const { format } = require('util');
12
- const CodeBuilder = require('../../helpers/code-builder');
13
- const helpers = require('./helpers');
14
- const headerHelpers = require('../../helpers/headers');
15
-
16
- module.exports = function (source, options) {
17
- const opts = {
18
- indent: ' ',
19
- pretty: true,
20
- ...options,
21
- };
22
-
23
- // Start snippet
24
- const code = new CodeBuilder(opts.indent);
25
-
26
- // Import requests
27
- code.push('import requests').blank();
28
-
29
- // Set URL
30
- code.push('url = "%s"', source.fullUrl).blank();
31
-
32
- const headers = source.allHeaders;
33
-
34
- // Construct payload
35
- let payload;
36
- let hasFiles = false;
37
- let hasPayload = false;
38
- let jsonPayload = false;
39
- switch (source.postData.mimeType) {
40
- case 'application/json':
41
- if (source.postData.jsonObj) {
42
- code.push('payload = %s', helpers.literalRepresentation(source.postData.jsonObj, opts));
43
- jsonPayload = true;
44
- hasPayload = true;
45
- }
46
- break;
47
-
48
- case 'multipart/form-data':
49
- if (source.postData.params) {
50
- const files = {};
51
- payload = {};
52
-
53
- source.postData.params.forEach(p => {
54
- if (p.fileName) {
55
- files[p.name] = `open('${p.fileName}', 'rb')`;
56
- hasFiles = true;
57
- } else {
58
- payload[p.name] = p.value;
59
- hasPayload = true;
60
- }
61
- });
62
-
63
- if (hasFiles) {
64
- code.push('files = %s', helpers.literalRepresentation(files, opts));
65
-
66
- if (hasPayload) {
67
- code.push('payload = %s', helpers.literalRepresentation(payload, opts));
68
- }
69
-
70
- // The requests library will only automatically add a `multipart/form-data` header if
71
- // there are files being sent. If we're **only** sending form data we still need to send
72
- // the boundary ourselves.
73
- delete headers[headerHelpers.getHeaderName(headers, 'content-type')];
74
- } else {
75
- payload = JSON.stringify(source.postData.text);
76
- if (payload) {
77
- code.push('payload = %s', payload);
78
- hasPayload = true;
79
- }
80
- }
81
- }
82
- break;
83
-
84
- default:
85
- payload = JSON.stringify(source.postData.text);
86
- if (payload) {
87
- code.push('payload = %s', payload);
88
- hasPayload = true;
89
- }
90
- }
91
-
92
- // Construct headers
93
- const headerCount = Object.keys(headers).length;
94
-
95
- if (!headerCount && (hasPayload || hasFiles)) {
96
- // If we don't have any heads but we do have a payload we should put a blank line here between
97
- // that payload consturction and our execution of the requests library.
98
- code.blank();
99
- } else if (headerCount === 1) {
100
- Object.keys(headers).forEach(header => {
101
- code.push('headers = {"%s": "%s"}', header, headers[header]).blank();
102
- });
103
- } else if (headerCount > 1) {
104
- let count = 1;
105
-
106
- code.push('headers = {');
107
-
108
- Object.keys(headers).forEach(header => {
109
- // eslint-disable-next-line no-plusplus
110
- if (count++ !== headerCount) {
111
- code.push(1, '"%s": "%s",', header, headers[header]);
112
- } else {
113
- code.push(1, '"%s": "%s"', header, headers[header]);
114
- }
115
- });
116
-
117
- code.push('}').blank();
118
- }
119
-
120
- // Construct request
121
- const method = source.method;
122
- let request;
123
- // Method list pulled from their api reference https://docs.python-requests.org/en/latest/api/#requests.head
124
- if (['HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'].includes(method)) {
125
- request = format('response = requests.%s(url', method.toLowerCase());
126
- } else {
127
- request = format('response = requests.request("%s", url', method);
128
- }
129
-
130
- if (hasPayload) {
131
- if (jsonPayload) {
132
- request += ', json=payload';
133
- } else {
134
- request += ', data=payload';
135
- }
136
- }
137
-
138
- if (hasFiles) {
139
- request += ', files=files';
140
- }
141
-
142
- if (headerCount > 0) {
143
- request += ', headers=headers';
144
- }
145
-
146
- request += ')';
147
-
148
- code.push(request).blank().push('print(response.text)');
149
-
150
- return (
151
- code
152
- .join()
153
- // The `open()` call must be a literal in the code snippet.
154
- .replace(/"open\('(.+)', 'rb'\)"/g, 'open("$1", "rb")')
155
- );
156
- };
157
-
158
- module.exports.info = {
159
- key: 'requests',
160
- title: 'Requests',
161
- link: 'http://docs.python-requests.org/en/latest/api/#requests.request',
162
- description: 'Requests HTTP library',
163
- };
@@ -1,134 +0,0 @@
1
- /**
2
- * @description
3
- * HTTP code snippet generator for R using httr
4
- *
5
- * @author
6
- * @gabrielakoreeda
7
- *
8
- * for any questions or issues regarding the generated code snippet, please open an issue mentioning the author.
9
- */
10
-
11
- const { format } = require('util');
12
- const CodeBuilder = require('../../helpers/code-builder');
13
-
14
- module.exports = function (source) {
15
- // Start snippet
16
- const code = new CodeBuilder();
17
-
18
- // Import httr
19
- code.push('library(httr)').blank();
20
-
21
- // Set URL
22
- code.push('url <- "%s"', source.url).blank();
23
-
24
- // Construct query string
25
- const qs = source.queryObj;
26
- // eslint-disable-next-line no-param-reassign
27
- delete source.queryObj.key;
28
-
29
- const queryCount = Object.keys(qs).length;
30
- if (queryCount === 1) {
31
- code.push('queryString <- list(%s = "%s")', Object.keys(qs), Object.values(qs).toString()).blank();
32
- } else if (queryCount > 1) {
33
- code.push('queryString <- list(');
34
-
35
- Object.keys(qs).forEach((query, i) => {
36
- if (i !== queryCount - 1) {
37
- code.push(' %s = "%s",', query, qs[query].toString());
38
- } else {
39
- code.push(' %s = "%s"', query, qs[query].toString());
40
- }
41
- });
42
-
43
- code.push(')').blank();
44
- }
45
-
46
- // Construct payload
47
- const payload = JSON.stringify(source.postData.text);
48
-
49
- if (payload) {
50
- code.push('payload <- %s', payload).blank();
51
- }
52
-
53
- // Define encode
54
- if (source.postData.text || source.postData.jsonObj || source.postData.params) {
55
- switch (source.postData.mimeType) {
56
- case 'application/x-www-form-urlencoded':
57
- code.push('encode <- "form"').blank();
58
- break;
59
-
60
- case 'application/json':
61
- code.push('encode <- "json"').blank();
62
- break;
63
-
64
- case 'multipart/form-data':
65
- code.push('encode <- "multipart"').blank();
66
- break;
67
-
68
- default:
69
- code.push('encode <- "raw"').blank();
70
- break;
71
- }
72
- }
73
-
74
- // Construct headers
75
- const headers = [];
76
- let cookies;
77
- let accept;
78
-
79
- Object.keys(source.allHeaders).forEach(header => {
80
- if (header.toLowerCase() === 'accept') {
81
- accept = `, accept("${source.allHeaders[header]}")`;
82
- } else if (header.toLowerCase() === 'cookie') {
83
- cookies = `, set_cookies(\`${source.allHeaders[header]
84
- .replace(/;/g, '", `')
85
- .replace(/` /g, '`')
86
- .replace(/=/g, '` = "')}")`;
87
- } else if (header.toLowerCase() !== 'content-type') {
88
- headers.push(`'${header}' = '${source.allHeaders[header]}'`);
89
- }
90
- });
91
-
92
- // Construct request
93
- const method = source.method;
94
- let request = format('response <- VERB("%s", url', method);
95
-
96
- if (payload) {
97
- request += ', body = payload';
98
- }
99
-
100
- if (headers.length) {
101
- request += `, add_headers(${headers.join(', ')})`;
102
- }
103
-
104
- if (source.queryString.length) {
105
- request += ', query = queryString';
106
- }
107
-
108
- request += `, content_type("${source.postData.mimeType}")`;
109
-
110
- if (typeof accept !== 'undefined') {
111
- request += accept;
112
- }
113
-
114
- if (typeof cookies !== 'undefined') {
115
- request += cookies;
116
- }
117
-
118
- if (source.postData.text || source.postData.jsonObj || source.postData.params) {
119
- request += ', encode = encode';
120
- }
121
-
122
- request += ')';
123
-
124
- code.push(request).blank().push('content(response, "text")');
125
-
126
- return code.join();
127
- };
128
-
129
- module.exports.info = {
130
- key: 'httr',
131
- title: 'httr',
132
- link: 'https://cran.r-project.org/web/packages/httr/vignettes/quickstart.html',
133
- description: 'httr: Tools for Working with URLs and HTTP',
134
- };
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- info: {
3
- key: 'r',
4
- title: 'R',
5
- extname: '.r',
6
- default: 'httr',
7
- },
8
-
9
- httr: require('./httr'),
10
- };
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- info: {
3
- key: 'ruby',
4
- title: 'Ruby',
5
- extname: '.rb',
6
- default: 'native',
7
- },
8
-
9
- native: require('./native'),
10
- };