@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
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # HTTP Snippet [![version][npm-version]][npm-url] [![License][npm-license]][license-url]
2
2
 
3
- > 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/kong/httpsnippet/wiki/Targets)!
3
+ > 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/Kong/httpsnippet/wiki/Targets)!
4
4
 
5
5
  Relies on the popular [HAR](http://www.softwareishard.com/blog/har-12-spec/#request) format to import data and describe HTTP calls.
6
6
 
7
- See it in action on companion service: [APIembed](https://apiembed.com/)
7
+ See it in action on [ReadMe](https://docs.readme.com/reference/getopenroles).
8
8
 
9
9
  [![Build](https://github.com/readmeio/httpsnippet/workflows/CI/badge.svg)](https://github.com/readmeio/httpsnippet)
10
10
 
@@ -20,17 +20,16 @@ npm install --save @readme/httpsnippet
20
20
 
21
21
  #### source
22
22
 
23
- *Required*
24
- Type: `object`
23
+ _Required_ Type: `object`
25
24
 
26
- Name of [conversion target](https://github.com/kong/httpsnippet/wiki/Targets)
25
+ Name of [conversion target](https://github.com/Kong/httpsnippet/wiki/Targets)
27
26
 
28
- ```js
29
- const HTTPSnippet = require('httpsnippet');
27
+ ```ts
28
+ import { HTTPSnippet } from 'httpsnippet';
30
29
 
31
30
  const snippet = new HTTPSnippet({
32
31
  method: 'GET',
33
- url: 'https://httpbin.com/anything'
32
+ url: 'https://httpbin.org/anything',
34
33
  });
35
34
  ```
36
35
 
@@ -46,130 +45,132 @@ Available options:
46
45
 
47
46
  #### target
48
47
 
49
- *Required*
50
- Type: `string`
48
+ _Required_ Type: `string`
51
49
 
52
- Name of [conversion target](https://github.com/kong/httpsnippet/wiki/Targets)
50
+ Name of [conversion target](https://github.com/Kong/httpsnippet/wiki/Targets)
53
51
 
54
52
  #### options
55
53
 
56
54
  Type: `object`
57
55
 
58
- Target options, *see [wiki](https://github.com/kong/httpsnippet/wiki/Targets) for details*
56
+ Target options, _see [wiki](https://github.com/Kong/httpsnippet/wiki/Targets) for details_
59
57
 
60
- ```js
61
- const HTTPSnippet = require('httpsnippet');
58
+ ```ts
59
+ import { HTTPSnippet } from 'httpsnippet';
62
60
 
63
61
  const snippet = new HTTPSnippet({
64
62
  method: 'GET',
65
- url: 'https://httpbin.com/anything'
63
+ url: 'httsp://httpbin.org/anything',
66
64
  });
67
65
 
68
66
  // generate Node.js: Native output
69
67
  console.log(snippet.convert('node'));
70
68
 
71
69
  // generate Node.js: Native output, indent with tabs
72
- console.log(snippet.convert('node', {
73
- indent: '\t'
74
- }));
70
+ console.log(
71
+ snippet.convert('node', {
72
+ indent: '\t',
73
+ }),
74
+ );
75
75
  ```
76
76
 
77
77
  ### convert(target [, client, options])
78
78
 
79
- #### target
79
+ #### Target
80
80
 
81
- *Required*
82
- Type: `string`
81
+ _Required_ Type: `string`
83
82
 
84
- Name of [conversion target](https://github.com/kong/httpsnippet/wiki/Targets)
83
+ Name of [conversion target](https://github.com/Kong/httpsnippet/wiki/Targets)
85
84
 
86
- #### client
85
+ #### Client
87
86
 
88
87
  Type: `string`
89
88
 
90
- Name of conversion target [client library](https://github.com/kong/httpsnippet/wiki/Targets)
89
+ Name of conversion target [client library](https://github.com/Kong/httpsnippet/wiki/Targets)
91
90
 
92
- #### options
91
+ #### Options
93
92
 
94
93
  Type: `object`
95
94
 
96
- Target options, *see [wiki](https://github.com/kong/httpsnippet/wiki/Targets) for details*
95
+ Target options, _see [wiki](https://github.com/Kong/httpsnippet/wiki/Targets) for details_
97
96
 
98
- ```js
99
- const HTTPSnippet = require('httpsnippet');
97
+ ```ts
98
+ import { HTTPSnippet } from 'httpsnippet';
100
99
 
101
100
  const snippet = new HTTPSnippet({
102
101
  method: 'GET',
103
- url: 'https://httpbin.com/anything'
102
+ url: 'https://httpbin.org/anything',
104
103
  });
105
104
 
106
105
  // generate Shell: cURL output
107
- console.log(snippet.convert('shell', 'curl', {
108
- indent: '\t'
109
- }));
106
+ console.log(
107
+ snippet.convert('shell', 'curl', {
108
+ indent: '\t',
109
+ }),
110
+ );
110
111
 
111
112
  // generate Node.js: Unirest output
112
113
  console.log(snippet.convert('node', 'unirest'));
113
114
  ```
114
115
 
115
116
  ### addTarget(target)
117
+
116
118
  #### target
117
119
 
118
- *Required*
119
- Type: `object`
120
+ _Required_ Type: `object`
120
121
 
121
122
  Representation of a [conversion target](https://github.com/Kong/httpsnippet/wiki/Creating-Targets). Can use this to use targets that are not officially supported.
122
123
 
123
- ```js
124
- const customLanguageTarget = require('httpsnippet-for-my-lang');
124
+ ```ts
125
+ import { customLanguageTarget } from 'httpsnippet-for-my-lang';
125
126
  HTTPSnippet.addTarget(customLanguageTarget);
126
127
  ```
127
128
 
128
129
  ### addTargetClient(target, client)
129
- ### target
130
130
 
131
- *Required*
132
- Type: `string`
131
+ ### Target
133
132
 
134
- Name of [conversion target](https://github.com/kong/httpsnippet/wiki/Targets)
133
+ _Required_ Type: `string`
135
134
 
136
- ### client
135
+ Name of [conversion target](https://github.com/Kong/httpsnippet/wiki/Targets)
137
136
 
138
- *Required*
139
- Type: `object`
137
+ ### Client
138
+
139
+ _Required_ Type: `object`
140
140
 
141
141
  Representation of a [conversion target client](https://github.com/Kong/httpsnippet/wiki/Creating-Targets). Can use this to use target clients that are not officially supported.
142
142
 
143
- ```js
144
- const customClient = require('httpsnippet-for-my-node-http-client');
143
+ ```ts
144
+ import { customClient } from 'httpsnippet-for-my-node-http-client';
145
145
  HTTPSnippet.addTargetClient('node', customClient);
146
146
  ```
147
147
 
148
148
  ## Documentation
149
149
 
150
- At the heart of this module is the [HAR Format](http://www.softwareishard.com/blog/har-12-spec/#request) as the HTTP request description format, please review some of the sample JSON HAR Request objects in [test fixtures](/__tests__/__fixtures__/requests), or read the [HAR Docs](http://www.softwareishard.com/blog/har-12-spec/#request) for more details.
150
+ At the heart of this module is the [HAR Format](http://www.softwareishard.com/blog/har-12-spec/#request) as the HTTP request description format, please review some of the sample JSON HAR Request objects in [test fixtures](/test/fixtures/requests), or read the [HAR Docs](http://www.softwareishard.com/blog/har-12-spec/#request) for more details.
151
151
 
152
- For detailed information on each target, please review the [wiki](https://github.com/kong/httpsnippet/wiki).
152
+ For detailed information on each target, please review the [wiki](https://github.com/Kong/httpsnippet/wiki).
153
153
 
154
154
  ## Differences from `kong/httpsnippet`
155
155
 
156
- The main difference between this library and the upstream [httpsnippet](https://github.com/Kong/httpsnippet) library are:
156
+ There are some major differences between this library and the [httpsnippet](https://github.com/Kong/httpsnippet) upstream:
157
157
 
158
+ * Includes a full integration test suite for a handful of clients and targets.
158
159
  * Does not ship with a CLI component.
159
- * The `fetch` target for Node and JS both treat body payloads as an object literal and wrap it within `JSON.stringify()`. We do this to keep those targets looking nicer with those kinds of payloads.
160
- * Contains a `harIsAlreadyEncoded` option on the core library to disable [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs. Helpful if the HAR being supplied already has them escaped.
161
- * PHP Guzzle snippets come with `require_once('vendor/autoload.php');` at the top of them.
162
- * A full integration suite for testing out snippets the library creates.
163
- * This library does not ship a Python client for [http.client](https://docs.python.org/3/library/http.client.html) due to its limitations in supporting file uploads.
164
-
165
- ### Running the integration suite
166
-
167
- ```
168
- docker-compose run integration_node
169
- docker-compose run integration_php
170
- docker-compose run integration_python
171
- docker-compose run integration_shell
172
- ```
160
+ * The main `HTTPSnippet` export contains an `options` argument for an `harIsAlreadyEncoded` option for disabling [escaping](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) of cookies and query strings in URLs.
161
+ * We added this because all HARs that we interact with already have this data escaped and this option prevents them from being double encoded, thus corrupting the data.
162
+ * Node
163
+ * `fetch`
164
+ * Body payloads are treated as an object literal and wrapped within `JSON.stringify()`. We do this to keep those targets looking nicer with those kinds of payloads. This also applies to the JS `fetch` target as wel.
165
+ * `request`
166
+ * Does not provide query string parameters in a `params` argument due to complexities with query encoding.
167
+ * PHP → `guzzle`
168
+ * Snippets have `require_once('vendor/autoload.php');` prefixed at the top.
169
+ * Python
170
+ * `python3`
171
+ * Does not ship this client due to its incompatibility with being able to support file uploads.
172
+ * `requests`
173
+ * Does not provide query string parameters in a `params` argument due to complexities with query encoding.
173
174
 
174
175
  ## License
175
176
 
@@ -0,0 +1,86 @@
1
+ {
2
+ "version": "4.0.2",
3
+ "name": "@readme/httpsnippet",
4
+ "description": "HTTP Request snippet generator for *most* languages",
5
+ "homepage": "https://github.com/readmeio/httpsnippet",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "keywords": [
10
+ "api",
11
+ "clojure",
12
+ "csharp",
13
+ "curl",
14
+ "go",
15
+ "har",
16
+ "http",
17
+ "httpie",
18
+ "httr",
19
+ "java",
20
+ "javascript",
21
+ "jquery",
22
+ "kotlin",
23
+ "objc",
24
+ "objective-c",
25
+ "ocaml",
26
+ "php",
27
+ "python",
28
+ "request",
29
+ "requests",
30
+ "ruby",
31
+ "shell",
32
+ "snippet",
33
+ "swift",
34
+ "swift",
35
+ "unirest",
36
+ "xhr",
37
+ "xmlhttprequest"
38
+ ],
39
+ "engines": {
40
+ "node": ">=14"
41
+ },
42
+ "files": [
43
+ "dist"
44
+ ],
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/readmeio/httpsnippet.git"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc --build tsconfig.build.json",
51
+ "clean": "tsc --build tsconfig.build.json --clean",
52
+ "lint": "eslint .",
53
+ "prebuild": "npm run clean",
54
+ "prepack": "npm run build",
55
+ "pretest": "npm run lint",
56
+ "prettier": "prettier --list-different --write \"./**/**.js\"",
57
+ "test": "jest --coverage"
58
+ },
59
+ "devDependencies": {
60
+ "@readme/eslint-config": "^8.8.3",
61
+ "@types/eslint": "^8.4.1",
62
+ "@types/event-stream": "^4.0.0",
63
+ "@types/har-format": "^1.2.8",
64
+ "@types/jest": "^27.4.1",
65
+ "@types/node": "^16.11.26",
66
+ "@types/qs": "^6.9.7",
67
+ "@types/stringify-object": "^4.0.1",
68
+ "eslint": "^8.19.0",
69
+ "glob": "^8.0.1",
70
+ "jest": "^28.0.3",
71
+ "prettier": "^2.7.1",
72
+ "require-directory": "^2.1.1",
73
+ "ts-jest": "^28.0.5",
74
+ "type-fest": "^2.12.2",
75
+ "typescript": "^4.6.3"
76
+ },
77
+ "dependencies": {
78
+ "ajv": "^6.12.6",
79
+ "event-stream": "4.0.1",
80
+ "form-data": "^4.0.0",
81
+ "har-schema": "^2.0.0",
82
+ "qs": "^6.10.1",
83
+ "stringify-object": "^3.3.0"
84
+ },
85
+ "prettier": "@readme/eslint-config/prettier"
86
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.customTarget = void 0;
4
+ var client_1 = require("../targets/node/request/client");
5
+ exports.customTarget = {
6
+ info: {
7
+ key: 'js-variant',
8
+ title: 'JavaScript Variant',
9
+ extname: '.js',
10
+ "default": 'request'
11
+ },
12
+ clientsById: {
13
+ request: client_1.request
14
+ }
15
+ };
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.mimetypes = void 0;
4
+ exports.mimetypes = {
5
+ 'multipart/mixed': {
6
+ method: 'POST',
7
+ url: 'https://httpbin.org/anything',
8
+ postData: {
9
+ mimeType: 'multipart/mixed',
10
+ text: ''
11
+ }
12
+ },
13
+ 'multipart/related': {
14
+ method: 'POST',
15
+ url: 'https://httpbin.org/anything',
16
+ postData: {
17
+ mimeType: 'multipart/related',
18
+ text: ''
19
+ }
20
+ },
21
+ 'multipart/form-data': {
22
+ method: 'POST',
23
+ url: 'https://httpbin.org/anything',
24
+ postData: {
25
+ mimeType: 'multipart/form-data',
26
+ text: ''
27
+ }
28
+ },
29
+ 'multipart/alternative': {
30
+ method: 'POST',
31
+ url: 'https://httpbin.org/anything',
32
+ postData: {
33
+ mimeType: 'multipart/alternative',
34
+ text: ''
35
+ }
36
+ },
37
+ 'application/x-www-form-urlencoded': {
38
+ method: 'POST',
39
+ url: 'https://httpbin.org/anything',
40
+ postData: {
41
+ mimeType: 'application/x-www-form-urlencoded',
42
+ text: ''
43
+ }
44
+ },
45
+ 'text/json': {
46
+ method: 'POST',
47
+ url: 'https://httpbin.org/anything',
48
+ postData: {
49
+ mimeType: 'text/json',
50
+ text: ''
51
+ }
52
+ },
53
+ 'text/x-json': {
54
+ method: 'POST',
55
+ url: 'https://httpbin.org/anything',
56
+ postData: {
57
+ mimeType: 'text/x-json',
58
+ text: ''
59
+ }
60
+ },
61
+ 'application/x-json': {
62
+ method: 'POST',
63
+ url: 'https://httpbin.org/anything',
64
+ postData: {
65
+ mimeType: 'application/x-json',
66
+ text: ''
67
+ }
68
+ },
69
+ 'invalid-json': {
70
+ method: 'POST',
71
+ url: 'https://httpbin.org/anything',
72
+ postData: {
73
+ mimeType: 'application/json',
74
+ text: 'foo/bar'
75
+ }
76
+ }
77
+ };
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ module.exports = {
3
+ log: {
4
+ version: '1.2',
5
+ creator: {
6
+ name: 'HTTPSnippet',
7
+ version: '1.0.0'
8
+ },
9
+ entries: [
10
+ {
11
+ request: {
12
+ method: 'POST',
13
+ url: 'https://httpbin.org/anything',
14
+ headers: [
15
+ {
16
+ name: 'content-type',
17
+ value: 'application/x-www-form-urlencoded'
18
+ },
19
+ ],
20
+ postData: {
21
+ mimeType: 'application/x-www-form-urlencoded',
22
+ params: [
23
+ {
24
+ name: 'foo',
25
+ value: 'bar'
26
+ },
27
+ {
28
+ name: 'hello',
29
+ value: 'world'
30
+ },
31
+ ]
32
+ }
33
+ },
34
+ response: {
35
+ status: 200,
36
+ statusText: 'OK',
37
+ httpVersion: 'HTTP/1.1',
38
+ headers: [
39
+ {
40
+ name: 'Content-Type',
41
+ value: 'application/json'
42
+ },
43
+ ],
44
+ content: {
45
+ size: -1,
46
+ mimeType: 'application/json',
47
+ text: JSON.stringify({
48
+ args: {},
49
+ data: '',
50
+ files: {},
51
+ form: {
52
+ foo: 'bar',
53
+ hello: 'world'
54
+ },
55
+ headers: {
56
+ 'Content-Type': 'application/x-www-form-urlencoded'
57
+ },
58
+ json: null,
59
+ method: 'POST',
60
+ url: 'https://httpbin.org/anything'
61
+ })
62
+ },
63
+ headersSize: -1,
64
+ bodySize: -1
65
+ }
66
+ },
67
+ ]
68
+ }
69
+ };
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ module.exports = {
3
+ log: {
4
+ version: '1.2',
5
+ creator: {
6
+ name: 'HTTPSnippet',
7
+ version: '1.0.0'
8
+ },
9
+ entries: [
10
+ {
11
+ request: {
12
+ method: 'POST',
13
+ url: 'https://httpbin.org/anything',
14
+ headers: [
15
+ {
16
+ name: 'content-type',
17
+ value: 'application/json'
18
+ },
19
+ ],
20
+ postData: {
21
+ mimeType: 'application/json',
22
+ text: '{"number":1,"string":"f\\"oo","arr":[1,2,3],"nested":{"a":"b"},"arr_mix":[1,"a",{"arr_mix_nested":{}}],"boolean":false}'
23
+ }
24
+ },
25
+ response: {
26
+ status: 200,
27
+ statusText: 'OK',
28
+ httpVersion: 'HTTP/1.1',
29
+ headers: [
30
+ {
31
+ name: 'Content-Type',
32
+ value: 'application/json'
33
+ },
34
+ ],
35
+ content: {
36
+ size: -1,
37
+ mimeType: 'application/json',
38
+ text: JSON.stringify({
39
+ args: {},
40
+ data: '{\n "number": 1,\n "string": "f\\"oo",\n "arr": [\n 1,\n 2,\n 3\n ],\n "nested": {\n "a": "b"\n },\n "arr_mix": [\n 1,\n "a",\n {\n "arr_mix_nested": {}\n }\n ],\n "boolean": false\n}',
41
+ files: {},
42
+ form: {},
43
+ headers: {
44
+ 'Content-Type': 'application/json'
45
+ },
46
+ json: {
47
+ arr: [1, 2, 3],
48
+ arr_mix: [
49
+ 1,
50
+ 'a',
51
+ {
52
+ arr_mix_nested: {}
53
+ },
54
+ ],
55
+ boolean: false,
56
+ nested: {
57
+ a: 'b'
58
+ },
59
+ number: 1,
60
+ string: 'f"oo'
61
+ },
62
+ method: 'POST',
63
+ url: 'https://httpbin.org/anything'
64
+ })
65
+ },
66
+ headersSize: -1,
67
+ bodySize: -1
68
+ }
69
+ },
70
+ ]
71
+ }
72
+ };
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ module.exports = {
3
+ log: {
4
+ version: '1.2',
5
+ creator: {
6
+ name: 'HTTPSnippet',
7
+ version: '1.0.0'
8
+ },
9
+ entries: [
10
+ {
11
+ request: {
12
+ method: 'GET',
13
+ url: 'https://httpbin.org/cookies',
14
+ cookies: [
15
+ {
16
+ name: 'foo',
17
+ value: 'bar'
18
+ },
19
+ {
20
+ name: 'bar',
21
+ value: 'baz'
22
+ },
23
+ ]
24
+ },
25
+ response: {
26
+ status: 200,
27
+ statusText: 'OK',
28
+ httpVersion: 'HTTP/1.1',
29
+ headers: [
30
+ {
31
+ name: 'Content-Type',
32
+ value: 'application/json'
33
+ },
34
+ ],
35
+ content: {
36
+ size: -1,
37
+ mimeType: 'application/json',
38
+ text: JSON.stringify({
39
+ cookies: {
40
+ bar: 'baz',
41
+ foo: 'bar'
42
+ }
43
+ })
44
+ },
45
+ headersSize: -1,
46
+ bodySize: -1
47
+ }
48
+ },
49
+ ]
50
+ }
51
+ };
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ module.exports = {
3
+ log: {
4
+ version: '1.2',
5
+ creator: {
6
+ name: 'HTTPSnippet',
7
+ version: '1.0.0'
8
+ },
9
+ entries: [
10
+ {
11
+ request: {
12
+ method: 'PROPFIND',
13
+ url: 'https://httpbin.org/anything'
14
+ },
15
+ response: {
16
+ status: 405,
17
+ statusText: 'Method Not Allowed',
18
+ httpVersion: 'HTTP/1.1',
19
+ headers: [
20
+ {
21
+ name: 'Content-Type',
22
+ value: 'text/html'
23
+ },
24
+ ],
25
+ content: {
26
+ size: -1,
27
+ mimeType: 'text/html',
28
+ text: [
29
+ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
30
+ '<title>405 Method Not Allowed</title>',
31
+ '<h1>Method Not Allowed</h1>',
32
+ '<p>The method is not allowed for the requested URL.</p>',
33
+ ].join('\n')
34
+ },
35
+ headersSize: -1,
36
+ bodySize: -1
37
+ }
38
+ },
39
+ ]
40
+ }
41
+ };