codegen.spec.js.snap 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. // Jest Snapshot v1, https://goo.gl/fbAQLP
  2. exports[`generate request for Golang Native generate GET request 1`] = `
  3. "req, err := http.NewRequest(\\"GET\\", \\"https://httpbin.org/path/to?a=b\\")
  4. req.Header.Set(\\"Authorization\\", \\"Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk\\")
  5. req.Header.Set(\\"h1\\", \\"h1v\\")
  6. req.Header.Set(\\"h2\\", \\"h2v\\")
  7. if err != nil {
  8. log.Fatalf(\\"An Error Occured %v\\", err)
  9. }
  10. client := &http.Client{}
  11. resp, err := client.Do(req)
  12. if err != nil {
  13. log.Fatalf(\\"An Error Occured %v\\", err)
  14. }
  15. defer resp.Body.Close()
  16. body, err := ioutil.ReadAll(resp.Body)
  17. if err != nil {
  18. log.Fatalln(err)
  19. }
  20. "
  21. `;
  22. exports[`generate request for Golang Native generate POST request for JSON 1`] = `
  23. "var reqBody = []byte(\`{\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"}\`)
  24. req, err := http.NewRequest(\\"POST\\", \\"https://httpbin.org/path/to?a=b\\", bytes.NewBuffer(reqBody))
  25. req.Header.Set(\\"Content-Type\\", \\"application/json\\")
  26. req.Header.Set(\\"Authorization\\", \\"Bearer abcdefghijklmn\\")
  27. req.Header.Set(\\"h1\\", \\"h1v\\")
  28. req.Header.Set(\\"h2\\", \\"h2v\\")
  29. if err != nil {
  30. log.Fatalf(\\"An Error Occured %v\\", err)
  31. }
  32. client := &http.Client{}
  33. resp, err := client.Do(req)
  34. if err != nil {
  35. log.Fatalf(\\"An Error Occured %v\\", err)
  36. }
  37. defer resp.Body.Close()
  38. body, err := ioutil.ReadAll(resp.Body)
  39. if err != nil {
  40. log.Fatalln(err)
  41. }
  42. "
  43. `;
  44. exports[`generate request for Golang Native generate POST request for XML 1`] = `
  45. "req.Header.Set(\\"Content-Type\\", \\"application/xml\\")
  46. req.Header.Set(\\"Authorization\\", \\"Bearer abcdefghijklmn\\")
  47. req.Header.Set(\\"h1\\", \\"h1v\\")
  48. req.Header.Set(\\"h2\\", \\"h2v\\")
  49. if err != nil {
  50. log.Fatalf(\\"An Error Occured %v\\", err)
  51. }
  52. client := &http.Client{}
  53. resp, err := client.Do(req)
  54. if err != nil {
  55. log.Fatalf(\\"An Error Occured %v\\", err)
  56. }
  57. defer resp.Body.Close()
  58. body, err := ioutil.ReadAll(resp.Body)
  59. if err != nil {
  60. log.Fatalln(err)
  61. }
  62. "
  63. `;
  64. exports[`generate request for Golang Native generate PUT request for www-form-urlencoded 1`] = `
  65. "req, err := http.NewRequest(\\"PUT\\", \\"https://httpbin.org/path/to?a=b\\", strings.NewReader(\\"foo=bar&baz=qux\\"))
  66. req.Header.Set(\\"Content-Type\\", \\"application/x-www-form-urlencoded\\")
  67. if err != nil {
  68. log.Fatalf(\\"An Error Occured %v\\", err)
  69. }
  70. client := &http.Client{}
  71. resp, err := client.Do(req)
  72. if err != nil {
  73. log.Fatalf(\\"An Error Occured %v\\", err)
  74. }
  75. defer resp.Body.Close()
  76. body, err := ioutil.ReadAll(resp.Body)
  77. if err != nil {
  78. log.Fatalln(err)
  79. }
  80. "
  81. `;
  82. exports[`generate request for JavaScript Axios generate GET request 1`] = `
  83. "axios.get('https://httpbin.org/path/to?a=b',{
  84. headers : { \\"h1\\": \\"h1v\\",
  85. \\"h2\\": \\"h2v\\",
  86. \\"Authorization\\": \\"Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk\\"}
  87. }.then(response => {
  88. console.log(response);
  89. }).catch(error => {
  90. console.log(error);
  91. })
  92. "
  93. `;
  94. exports[`generate request for JavaScript Axios generate POST request for JSON 1`] = `
  95. "axios.post('https://httpbin.org/path/to?a=b',{
  96. headers : { \\"h1\\": \\"h1v\\",
  97. \\"h2\\": \\"h2v\\",
  98. \\"Content-Type\\": \\"application/json; charset=utf-8\\",
  99. \\"Authorization\\": \\"Bearer abcdefghijklmn\\"}
  100. }.then(response => {
  101. console.log(response);
  102. }).catch(error => {
  103. console.log(error);
  104. })
  105. "
  106. `;
  107. exports[`generate request for JavaScript Axios generate POST request for XML 1`] = `
  108. "axios.post('https://httpbin.org/path/to?a=b',{
  109. headers : { \\"h1\\": \\"h1v\\",
  110. \\"h2\\": \\"h2v\\",
  111. \\"Content-Type\\": \\"application/xml; charset=utf-8\\",
  112. \\"Authorization\\": \\"Bearer abcdefghijklmn\\"}
  113. }.then(response => {
  114. console.log(response);
  115. }).catch(error => {
  116. console.log(error);
  117. })
  118. "
  119. `;
  120. exports[`generate request for JavaScript Axios generate PUT request for www-form-urlencoded 1`] = `
  121. "axios.put('https://httpbin.org/path/to?a=b', foo=bar&baz=qux,{
  122. headers : {\\"Content-Type\\": \\"application/x-www-form-urlencoded; charset=utf-8\\"}
  123. }.then(response => {
  124. console.log(response);
  125. }).catch(error => {
  126. console.log(error);
  127. })
  128. "
  129. `;
  130. exports[`generate request for JavaScript Fetch generate GET request 1`] = `
  131. "fetch(\\"https://httpbin.org/path/to?a=b\\", {
  132. method: \\"GET\\",
  133. headers: {
  134. \\"Authorization\\": \\"Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk\\",
  135. \\"h1\\": \\"h1v\\",
  136. \\"h2\\": \\"h2v\\"
  137. },
  138. credentials: \\"same-origin\\"
  139. }).then(function(response) {
  140. response.status
  141. response.statusText
  142. response.headers
  143. response.url
  144. return response.text()
  145. }).catch(function(error) {
  146. error.message
  147. })"
  148. `;
  149. exports[`generate request for JavaScript Fetch generate POST request for JSON 1`] = `
  150. "fetch(\\"https://httpbin.org/path/to?a=b\\", {
  151. method: \\"POST\\",
  152. body: JSON.stringify({\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"}),
  153. headers: {
  154. \\"Authorization\\": \\"Bearer abcdefghijklmn\\",
  155. \\"Content-Type\\": \\"application/json; charset=utf-8\\",
  156. \\"h1\\": \\"h1v\\",
  157. \\"h2\\": \\"h2v\\"
  158. },
  159. credentials: \\"same-origin\\"
  160. }).then(function(response) {
  161. response.status
  162. response.statusText
  163. response.headers
  164. response.url
  165. return response.text()
  166. }).catch(function(error) {
  167. error.message
  168. })"
  169. `;
  170. exports[`generate request for JavaScript Fetch generate POST request for XML 1`] = `
  171. "fetch(\\"https://httpbin.org/path/to?a=b\\", {
  172. method: \\"POST\\",
  173. body: <?xml version='1.0' encoding='utf-8'?>
  174. <xml>
  175. <element foo=\\"bar\\"></element>
  176. </xml>,
  177. headers: {
  178. \\"Authorization\\": \\"Bearer abcdefghijklmn\\",
  179. \\"Content-Type\\": \\"application/xml; charset=utf-8\\",
  180. \\"h1\\": \\"h1v\\",
  181. \\"h2\\": \\"h2v\\"
  182. },
  183. credentials: \\"same-origin\\"
  184. }).then(function(response) {
  185. response.status
  186. response.statusText
  187. response.headers
  188. response.url
  189. return response.text()
  190. }).catch(function(error) {
  191. error.message
  192. })"
  193. `;
  194. exports[`generate request for JavaScript Fetch generate PUT request for www-form-urlencoded 1`] = `
  195. "fetch(\\"https://httpbin.org/path/to?a=b\\", {
  196. method: \\"PUT\\",
  197. body: \\"foo=bar&baz=qux\\",
  198. headers: {
  199. \\"Content-Type\\": \\"application/x-www-form-urlencoded; charset=utf-8\\"
  200. },
  201. credentials: \\"same-origin\\"
  202. }).then(function(response) {
  203. response.status
  204. response.statusText
  205. response.headers
  206. response.url
  207. return response.text()
  208. }).catch(function(error) {
  209. error.message
  210. })"
  211. `;
  212. exports[`generate request for JavaScript XHR generate GET request 1`] = `
  213. "const xhr = new XMLHttpRequest()
  214. xhr.open('GET', 'https://httpbin.org/path/to?a=b', true, 'mockUser', 'mockPassword')
  215. xhr.setRequestHeader('h1', 'h1v')
  216. xhr.setRequestHeader('h2', 'h2v')
  217. xhr.send()"
  218. `;
  219. exports[`generate request for JavaScript XHR generate POST request for JSON 1`] = `
  220. "const xhr = new XMLHttpRequest()
  221. xhr.open('POST', 'https://httpbin.org/path/to?a=b', true, null, null)
  222. xhr.setRequestHeader('Authorization', 'Bearer abcdefghijklmn')
  223. xhr.setRequestHeader('h1', 'h1v')
  224. xhr.setRequestHeader('h2', 'h2v')
  225. xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8')
  226. xhr.send(JSON.stringify({\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"}))"
  227. `;
  228. exports[`generate request for JavaScript XHR generate POST request for XML 1`] = `
  229. "const xhr = new XMLHttpRequest()
  230. xhr.open('POST', 'https://httpbin.org/path/to?a=b', true, null, null)
  231. xhr.setRequestHeader('Authorization', 'Bearer abcdefghijklmn')
  232. xhr.setRequestHeader('h1', 'h1v')
  233. xhr.setRequestHeader('h2', 'h2v')
  234. xhr.setRequestHeader('Content-Type', 'application/xml; charset=utf-8')
  235. xhr.send(<?xml version='1.0' encoding='utf-8'?>
  236. <xml>
  237. <element foo=\\"bar\\"></element>
  238. </xml>)"
  239. `;
  240. exports[`generate request for JavaScript XHR generate PUT request for www-form-urlencoded 1`] = `
  241. "const xhr = new XMLHttpRequest()
  242. xhr.open('PUT', 'https://httpbin.org/path/to?a=b', true, null, null)
  243. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8')
  244. xhr.send(\\"foo=bar&baz=qux\\")"
  245. `;
  246. exports[`generate request for JavaScript jQuery generate GET request 1`] = `
  247. "jQuery.ajax({
  248. url: \\"https://httpbin.org/path/to?a=b\\",
  249. method: \\"GET\\",
  250. headers: {
  251. \\"h1\\": \\"h1v\\",
  252. \\"h2\\": \\"h2v\\",
  253. \\"Authorization\\": \\"Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk\\"
  254. }
  255. }).then(response => {
  256. console.log(response);
  257. }).catch(error => {
  258. console.log(error);
  259. })
  260. "
  261. `;
  262. exports[`generate request for JavaScript jQuery generate POST request for JSON 1`] = `
  263. "jQuery.ajax({
  264. url: \\"https://httpbin.org/path/to?a=b\\",
  265. method: \\"POST\\",
  266. body: {\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"},
  267. contentType: \\"application/json; charset=utf-8\\",
  268. headers: {
  269. \\"h1\\": \\"h1v\\",
  270. \\"h2\\": \\"h2v\\",
  271. \\"Content-Type\\": \\"application/json; charset=utf-8\\",
  272. \\"Authorization\\": \\"Bearer abcdefghijklmn\\"
  273. }
  274. }).then(response => {
  275. console.log(response);
  276. }).catch(error => {
  277. console.log(error);
  278. })
  279. "
  280. `;
  281. exports[`generate request for JavaScript jQuery generate POST request for XML 1`] = `
  282. "jQuery.ajax({
  283. url: \\"https://httpbin.org/path/to?a=b\\",
  284. method: \\"POST\\",
  285. body: <?xml version='1.0' encoding='utf-8'?>
  286. <xml>
  287. <element foo=\\"bar\\"></element>
  288. </xml>,
  289. contentType: \\"application/xml; charset=utf-8\\",
  290. headers: {
  291. \\"h1\\": \\"h1v\\",
  292. \\"h2\\": \\"h2v\\",
  293. \\"Content-Type\\": \\"application/xml; charset=utf-8\\",
  294. \\"Authorization\\": \\"Bearer abcdefghijklmn\\"
  295. }
  296. }).then(response => {
  297. console.log(response);
  298. }).catch(error => {
  299. console.log(error);
  300. })
  301. "
  302. `;
  303. exports[`generate request for JavaScript jQuery generate PUT request for www-form-urlencoded 1`] = `
  304. "jQuery.ajax({
  305. url: \\"https://httpbin.org/path/to?a=b\\",
  306. method: \\"PUT\\",
  307. body: foo=bar&baz=qux,
  308. contentType: \\"application/x-www-form-urlencoded; charset=utf-8\\",
  309. headers: {
  310. \\"Content-Type\\": \\"application/x-www-form-urlencoded; charset=utf-8\\"
  311. }
  312. }).then(response => {
  313. console.log(response);
  314. }).catch(error => {
  315. console.log(error);
  316. })
  317. "
  318. `;
  319. exports[`generate request for NodeJs Native generate GET request 1`] = `
  320. "const http = require('http');
  321. const url = 'https://httpbin.org/path/to?a=b';
  322. const options = {
  323. method: 'GET',
  324. headers: {
  325. \\"Authorization\\": \\"Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk\\",
  326. \\"h1\\": \\"h1v\\",
  327. \\"h2\\": \\"h2v\\"
  328. }};
  329. const request = http.request(url, options, (response) => {
  330. console.log(response);
  331. });
  332. request.on('error', (e) => {
  333. console.error(e);
  334. });
  335. request.end();"
  336. `;
  337. exports[`generate request for NodeJs Native generate POST request for JSON 1`] = `
  338. "const http = require('http');
  339. const url = 'https://httpbin.org/path/to?a=b';
  340. const options = {
  341. method: 'POST',
  342. headers: {
  343. \\"Authorization\\": \\"Bearer abcdefghijklmn\\",
  344. \\"Content-Type\\": \\"application/json; charset=utf-8\\",
  345. \\"h1\\": \\"h1v\\",
  346. \\"h2\\": \\"h2v\\"
  347. }};
  348. const request = http.request(url, options, (response) => {
  349. console.log(response);
  350. });
  351. request.on('error', (e) => {
  352. console.error(e);
  353. });
  354. request.write(JSON.stringify({\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"}));
  355. request.end();"
  356. `;
  357. exports[`generate request for NodeJs Native generate POST request for XML 1`] = `
  358. "const http = require('http');
  359. const url = 'https://httpbin.org/path/to?a=b';
  360. const options = {
  361. method: 'POST',
  362. headers: {
  363. \\"Authorization\\": \\"Bearer abcdefghijklmn\\",
  364. \\"Content-Type\\": \\"application/xml; charset=utf-8\\",
  365. \\"h1\\": \\"h1v\\",
  366. \\"h2\\": \\"h2v\\"
  367. }};
  368. const request = http.request(url, options, (response) => {
  369. console.log(response);
  370. });
  371. request.on('error', (e) => {
  372. console.error(e);
  373. });
  374. request.write(\`<?xml version='1.0' encoding='utf-8'?>
  375. <xml>
  376. <element foo=\\"bar\\"></element>
  377. </xml>\`);
  378. request.end();"
  379. `;
  380. exports[`generate request for NodeJs Native generate PUT request for www-form-urlencoded 1`] = `
  381. "const http = require('http');
  382. const url = 'https://httpbin.org/path/to?a=b';
  383. const options = {
  384. method: 'PUT',
  385. headers: {
  386. \\"Content-Type\\": \\"application/x-www-form-urlencoded; charset=utf-8\\"
  387. }};
  388. const request = http.request(url, options, (response) => {
  389. console.log(response);
  390. });
  391. request.on('error', (e) => {
  392. console.error(e);
  393. });
  394. request.write(\`foo=bar&baz=qux\`);
  395. request.end();"
  396. `;
  397. exports[`generate request for NodeJs Request generate GET request 1`] = `
  398. "const request = require('request');
  399. const options = {
  400. method: 'get',
  401. url: 'https://httpbin.org/path/to?a=b',
  402. headers: {
  403. \\"Authorization\\": \\"Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk\\",
  404. \\"h1\\": \\"h1v\\",
  405. \\"h2\\": \\"h2v\\"
  406. }
  407. }
  408. request(options, (error, response) => {
  409. if (error) throw new Error(error);
  410. console.log(response.body);
  411. });"
  412. `;
  413. exports[`generate request for NodeJs Request generate POST request for JSON 1`] = `
  414. "const request = require('request');
  415. const options = {
  416. method: 'post',
  417. url: 'https://httpbin.org/path/to?a=b',
  418. body: JSON.stringify({\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"}),
  419. headers: {
  420. \\"Authorization\\": \\"Bearer abcdefghijklmn\\",
  421. \\"Content-Type\\": \\"application/json; charset=utf-8\\",
  422. \\"h1\\": \\"h1v\\",
  423. \\"h2\\": \\"h2v\\"
  424. }
  425. }
  426. request(options, (error, response) => {
  427. if (error) throw new Error(error);
  428. console.log(response.body);
  429. });"
  430. `;
  431. exports[`generate request for NodeJs Request generate POST request for XML 1`] = `
  432. "const request = require('request');
  433. const options = {
  434. method: 'post',
  435. url: 'https://httpbin.org/path/to?a=b',
  436. body: \`<?xml version='1.0' encoding='utf-8'?>
  437. <xml>
  438. <element foo=\\"bar\\"></element>
  439. </xml>\`,
  440. headers: {
  441. \\"Authorization\\": \\"Bearer abcdefghijklmn\\",
  442. \\"Content-Type\\": \\"application/xml; charset=utf-8\\",
  443. \\"h1\\": \\"h1v\\",
  444. \\"h2\\": \\"h2v\\"
  445. }
  446. }
  447. request(options, (error, response) => {
  448. if (error) throw new Error(error);
  449. console.log(response.body);
  450. });"
  451. `;
  452. exports[`generate request for NodeJs Request generate PUT request for www-form-urlencoded 1`] = `
  453. "const request = require('request');
  454. const options = {
  455. method: 'put',
  456. url: 'https://httpbin.org/path/to?a=b',
  457. form: {\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"},
  458. headers: {
  459. \\"Content-Type\\": \\"application/x-www-form-urlencoded; charset=utf-8\\"
  460. }
  461. }
  462. request(options, (error, response) => {
  463. if (error) throw new Error(error);
  464. console.log(response.body);
  465. });"
  466. `;
  467. exports[`generate request for PHP cURL generate GET request 1`] = `
  468. <?php
  469. $curl = curl_init();
  470. curl_setopt_array($curl, array(
  471. CURLOPT_URL => "https://httpbin.org/path/to?a=b",
  472. CURLOPT_RETURNTRANSFER => true,
  473. CURLOPT_ENCODING => "",
  474. CURLOPT_MAXREDIRS => 10,
  475. CURLOPT_TIMEOUT => 0,
  476. CURLOPT_FOLLOWLOCATION => true,
  477. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  478. CURLOPT_CUSTOMREQUEST => "GET",
  479. CURLOPT_HTTPHEADER => array(
  480. "Authorization: Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk",
  481. "h1: h1v",
  482. "h2: h2v"
  483. )
  484. ));
  485. $response = curl_exec($curl);
  486. curl_close($curl);
  487. echo $response;
  488. `;
  489. exports[`generate request for PHP cURL generate POST request for JSON 1`] = `
  490. <?php
  491. $curl = curl_init();
  492. curl_setopt_array($curl, array(
  493. CURLOPT_URL => "https://httpbin.org/path/to?a=b",
  494. CURLOPT_RETURNTRANSFER => true,
  495. CURLOPT_ENCODING => "",
  496. CURLOPT_MAXREDIRS => 10,
  497. CURLOPT_TIMEOUT => 0,
  498. CURLOPT_FOLLOWLOCATION => true,
  499. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  500. CURLOPT_CUSTOMREQUEST => "POST",
  501. CURLOPT_POSTFIELDS => "{\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"}",
  502. CURLOPT_HTTPHEADER => array(
  503. "Authorization: Bearer abcdefghijklmn",
  504. "Content-Type: application/json; charset=utf-8",
  505. "h1: h1v",
  506. "h2: h2v"
  507. )
  508. ));
  509. $response = curl_exec($curl);
  510. curl_close($curl);
  511. echo $response;
  512. `;
  513. exports[`generate request for PHP cURL generate POST request for XML 1`] = `
  514. <?php
  515. $curl = curl_init();
  516. curl_setopt_array($curl, array(
  517. CURLOPT_URL => "https://httpbin.org/path/to?a=b",
  518. CURLOPT_RETURNTRANSFER => true,
  519. CURLOPT_ENCODING => "",
  520. CURLOPT_MAXREDIRS => 10,
  521. CURLOPT_TIMEOUT => 0,
  522. CURLOPT_FOLLOWLOCATION => true,
  523. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  524. CURLOPT_CUSTOMREQUEST => "POST",
  525. CURLOPT_POSTFIELDS => array(<?xmlversion='1.0'encoding='utf-8'?><xml>
  526. <elementfoo="bar">
  527. </element>
  528. </xml>),
  529. CURLOPT_HTTPHEADER => array(
  530. "Authorization: Bearer abcdefghijklmn",
  531. "Content-Type: application/xml; charset=utf-8",
  532. "h1: h1v",
  533. "h2: h2v"
  534. )
  535. ));
  536. $response = curl_exec($curl);
  537. curl_close($curl);
  538. echo $response;
  539. `;
  540. exports[`generate request for PHP cURL generate PUT request for www-form-urlencoded 1`] = `
  541. <?php
  542. $curl = curl_init();
  543. curl_setopt_array($curl, array(
  544. CURLOPT_URL => "https://httpbin.org/path/to?a=b",
  545. CURLOPT_RETURNTRANSFER => true,
  546. CURLOPT_ENCODING => "",
  547. CURLOPT_MAXREDIRS => 10,
  548. CURLOPT_TIMEOUT => 0,
  549. CURLOPT_FOLLOWLOCATION => true,
  550. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  551. CURLOPT_CUSTOMREQUEST => "PUT",
  552. CURLOPT_POSTFIELDS => "foo=bar&baz=qux",
  553. CURLOPT_HTTPHEADER => array(
  554. "Content-Type: application/x-www-form-urlencoded; charset=utf-8"
  555. )
  556. ));
  557. $response = curl_exec($curl);
  558. curl_close($curl);
  559. echo $response;
  560. `;
  561. exports[`generate request for Powershell RestMethod generate GET request 1`] = `
  562. "$headers = @{
  563. 'h1' = 'h1v'
  564. 'h2' = 'h2v'
  565. 'Authorization' = 'Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk'
  566. }
  567. Invoke-RestMethod -Method 'Get' -Uri 'https://httpbin.org/path/to?a=b' -Headers $headers"
  568. `;
  569. exports[`generate request for Powershell RestMethod generate POST request for JSON 1`] = `
  570. "$body = @'
  571. {\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"}
  572. '@
  573. $headers = @{
  574. 'h1' = 'h1v'
  575. 'h2' = 'h2v'
  576. 'Content-Type' = 'application/json; charset=utf-8'
  577. 'Authorization' = 'Bearer abcdefghijklmn'
  578. }
  579. Invoke-RestMethod -Method 'Post' -Uri 'https://httpbin.org/path/to?a=b' -ContentType 'application/json; charset=utf-8' -Headers $headers -Body $body"
  580. `;
  581. exports[`generate request for Powershell RestMethod generate POST request for XML 1`] = `
  582. "$body = @'
  583. <?xml version='1.0' encoding='utf-8'?>
  584. <xml>
  585. <element foo=\\"bar\\"></element>
  586. </xml>
  587. '@
  588. $headers = @{
  589. 'h1' = 'h1v'
  590. 'h2' = 'h2v'
  591. 'Content-Type' = 'application/xml; charset=utf-8'
  592. 'Authorization' = 'Bearer abcdefghijklmn'
  593. }
  594. Invoke-RestMethod -Method 'Post' -Uri 'https://httpbin.org/path/to?a=b' -ContentType 'application/xml; charset=utf-8' -Headers $headers -Body $body"
  595. `;
  596. exports[`generate request for Powershell RestMethod generate PUT request for www-form-urlencoded 1`] = `
  597. "$body = @'
  598. foo=bar&baz=qux
  599. '@
  600. $headers = @{
  601. 'Content-Type' = 'application/x-www-form-urlencoded; charset=utf-8'
  602. }
  603. Invoke-RestMethod -Method 'Put' -Uri 'https://httpbin.org/path/to?a=b' -ContentType 'application/x-www-form-urlencoded; charset=utf-8' -Headers $headers -Body $body"
  604. `;
  605. exports[`generate request for Python HTTP Client generate GET request 1`] = `
  606. "import http.client
  607. import mimetypes
  608. conn = http.client.HTTPSConnection(\\"httpbin.org\\")
  609. headers = {
  610. 'Authorization': 'Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk',
  611. 'h1': 'h1v',
  612. 'h2': 'h2v'
  613. }
  614. payload = ''
  615. conn.request(\\"GET\\", \\"/path/to?a=b\\", payload, headers)
  616. res = conn.getresponse()
  617. data = res.read()
  618. print(data.decode(\\"utf-8\\"))"
  619. `;
  620. exports[`generate request for Python HTTP Client generate POST request for JSON 1`] = `
  621. "import http.client
  622. import mimetypes
  623. conn = http.client.HTTPSConnection(\\"httpbin.org\\")
  624. headers = {
  625. 'Authorization': 'Bearer abcdefghijklmn',
  626. 'h1': 'h1v',
  627. 'h2': 'h2v',
  628. 'Content-Type': 'application/json'
  629. }
  630. payload = \\"{\\\\\\"foo\\\\\\": \\\\\\"bar\\\\\\", \\\\\\"baz\\\\\\": \\\\\\"qux\\\\\\"}\\"
  631. conn.request(\\"POST\\", \\"/path/to?a=b\\", payload, headers)
  632. res = conn.getresponse()
  633. data = res.read()
  634. print(data.decode(\\"utf-8\\"))"
  635. `;
  636. exports[`generate request for Python HTTP Client generate POST request for XML 1`] = `
  637. "import http.client
  638. import mimetypes
  639. conn = http.client.HTTPSConnection(\\"httpbin.org\\")
  640. headers = {
  641. 'Authorization': 'Bearer abcdefghijklmn',
  642. 'h1': 'h1v',
  643. 'h2': 'h2v',
  644. 'Content-Type': 'application/xml'
  645. }
  646. paylod = '''<?xml version='1.0' encoding='utf-8'?>
  647. <xml>
  648. <element foo=\\"bar\\"></element>
  649. </xml>'''
  650. conn.request(\\"POST\\", \\"/path/to?a=b\\", payload, headers)
  651. res = conn.getresponse()
  652. data = res.read()
  653. print(data.decode(\\"utf-8\\"))"
  654. `;
  655. exports[`generate request for Python HTTP Client generate PUT request for www-form-urlencoded 1`] = `
  656. "import http.client
  657. import mimetypes
  658. conn = http.client.HTTPSConnection(\\"httpbin.org\\")
  659. headers = {
  660. 'Content-Type': 'application/x-www-form-urlencoded'
  661. }
  662. payload = [('foo', 'bar'),
  663. ('baz', 'qux')]
  664. conn.request(\\"PUT\\", \\"/path/to?a=b\\", payload, headers)
  665. res = conn.getresponse()
  666. data = res.read()
  667. print(data.decode(\\"utf-8\\"))"
  668. `;
  669. exports[`generate request for Python Requests generate GET request 1`] = `
  670. "import requests
  671. url = 'https://httpbin.org/path/to?a=b'
  672. headers = {
  673. 'Authorization': 'Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk',
  674. 'h1': 'h1v',
  675. 'h2': 'h2v'
  676. }
  677. response = requests.request(
  678. 'GET',
  679. 'https://httpbin.org/path/to?a=b',
  680. headers=headers,
  681. )
  682. print(response)"
  683. `;
  684. exports[`generate request for Python Requests generate POST request for JSON 1`] = `
  685. "import requests
  686. url = 'https://httpbin.org/path/to?a=b'
  687. headers = {
  688. 'Authorization': 'Bearer abcdefghijklmn',
  689. 'h1': 'h1v',
  690. 'h2': 'h2v',
  691. 'Content-Type': 'application/json'
  692. }
  693. data = \\"{\\\\\\"foo\\\\\\": \\\\\\"bar\\\\\\", \\\\\\"baz\\\\\\": \\\\\\"qux\\\\\\"}\\"
  694. response = requests.request(
  695. 'POST',
  696. 'https://httpbin.org/path/to?a=b',
  697. data=data,
  698. headers=headers,
  699. )
  700. print(response)"
  701. `;
  702. exports[`generate request for Python Requests generate POST request for XML 1`] = `
  703. "import requests
  704. url = 'https://httpbin.org/path/to?a=b'
  705. headers = {
  706. 'Authorization': 'Bearer abcdefghijklmn',
  707. 'h1': 'h1v',
  708. 'h2': 'h2v',
  709. 'Content-Type': 'application/xml'
  710. }
  711. data = '''<?xml version='1.0' encoding='utf-8'?>
  712. <xml>
  713. <element foo=\\"bar\\"></element>
  714. </xml>'''
  715. response = requests.request(
  716. 'POST',
  717. 'https://httpbin.org/path/to?a=b',
  718. data=data,
  719. headers=headers,
  720. )
  721. print(response)"
  722. `;
  723. exports[`generate request for Python Requests generate PUT request for www-form-urlencoded 1`] = `
  724. "import requests
  725. url = 'https://httpbin.org/path/to?a=b'
  726. headers = {
  727. 'Content-Type': 'application/x-www-form-urlencoded'
  728. }
  729. data = [('foo', 'bar'),
  730. ('baz', 'qux')]
  731. response = requests.request(
  732. 'PUT',
  733. 'https://httpbin.org/path/to?a=b',
  734. data=data,
  735. headers=headers,
  736. )
  737. print(response)"
  738. `;
  739. exports[`generate request for cURL generate GET request 1`] = `
  740. "curl -X GET \\\\
  741. 'https://httpbin.org/path/to?a=b' \\\\
  742. -H 'Authorization: Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk' \\\\
  743. -H 'h1: h1v' \\\\
  744. -H 'h2: h2v'"
  745. `;
  746. exports[`generate request for cURL generate POST request for JSON 1`] = `
  747. "curl -X POST \\\\
  748. 'https://httpbin.org/path/to?a=b' \\\\
  749. -H 'Authorization: Bearer abcdefghijklmn' \\\\
  750. -H 'h1: h1v' \\\\
  751. -H 'h2: h2v' \\\\
  752. -H 'Content-Type: application/json; charset=utf-8' \\\\
  753. -d '{\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"}'"
  754. `;
  755. exports[`generate request for cURL generate POST request for XML 1`] = `
  756. "curl -X POST \\\\
  757. 'https://httpbin.org/path/to?a=b' \\\\
  758. -H 'Authorization: Bearer abcdefghijklmn' \\\\
  759. -H 'h1: h1v' \\\\
  760. -H 'h2: h2v' \\\\
  761. -H 'Content-Type: application/xml; charset=utf-8' \\\\
  762. -d '<?xml version='1.0' encoding='utf-8'?>
  763. <xml>
  764. <element foo=\\"bar\\"></element>
  765. </xml>'"
  766. `;
  767. exports[`generate request for cURL generate PUT request for www-form-urlencoded 1`] = `
  768. "curl -X PUT \\\\
  769. 'https://httpbin.org/path/to?a=b' \\\\
  770. -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \\\\
  771. -d 'foo=bar&baz=qux'"
  772. `;
  773. exports[`generate request for wget generate GET request 1`] = `
  774. "wget -O - --method=GET \\\\
  775. 'https://httpbin.org/path/to?a=b' \\\\
  776. --header='Authorization: Basic bW9ja1VzZXI6bW9ja1Bhc3N3b3Jk' \\\\
  777. --header='h1: h1v' \\\\
  778. --header='h2: h2v'"
  779. `;
  780. exports[`generate request for wget generate POST request for JSON 1`] = `
  781. "wget -O - --method=POST \\\\
  782. 'https://httpbin.org/path/to?a=b' \\\\
  783. --header='Authorization: Bearer abcdefghijklmn' \\\\
  784. --header='h1: h1v' \\\\
  785. --header='h2: h2v' \\\\
  786. --header='Content-Type: application/json; charset=utf-8' \\\\
  787. --body-data='{\\"foo\\": \\"bar\\", \\"baz\\": \\"qux\\"}'"
  788. `;
  789. exports[`generate request for wget generate POST request for XML 1`] = `
  790. "wget -O - --method=POST \\\\
  791. 'https://httpbin.org/path/to?a=b' \\\\
  792. --header='Authorization: Bearer abcdefghijklmn' \\\\
  793. --header='h1: h1v' \\\\
  794. --header='h2: h2v' \\\\
  795. --header='Content-Type: application/xml; charset=utf-8' \\\\
  796. --body-data='<?xml version='1.0' encoding='utf-8'?>
  797. <xml>
  798. <element foo=\\"bar\\"></element>
  799. </xml>'"
  800. `;
  801. exports[`generate request for wget generate PUT request for www-form-urlencoded 1`] = `
  802. "wget -O - --method=PUT \\\\
  803. 'https://httpbin.org/path/to?a=b' \\\\
  804. --header='Content-Type: application/x-www-form-urlencoded; charset=utf-8' \\\\
  805. --body-data='foo=bar&baz=qux'"
  806. `;