@readme/httpsnippet 4.0.3 → 4.0.4

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.
@@ -69,6 +69,17 @@ var validateHarRequest = function (request) {
69
69
  }
70
70
  var valid = validate(request);
71
71
  if (!valid && validate.errors) {
72
+ if (validate.errors.length === 1) {
73
+ // While not ideal, or compliant with the HAR spec, if we have an empty `postData` object in
74
+ // our HAR and no other errors we should let this through because it's fine and our client
75
+ // targets are able to handle it okay.
76
+ var error = validate.errors[0];
77
+ if (error.dataPath === '.postData' &&
78
+ error.message === "should have required property 'mimeType'" &&
79
+ JSON.stringify(request.postData) === '{}') {
80
+ return true;
81
+ }
82
+ }
72
83
  throw new HARError(validate.errors);
73
84
  }
74
85
  return true;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ var axios_1 = __importDefault(require("axios"));
7
+ var options = {
8
+ method: 'POST',
9
+ url: 'https://httpbin.org/anything',
10
+ headers: { 'content-type': 'application/json' }
11
+ };
12
+ axios_1["default"]
13
+ .request(options)
14
+ .then(function (response) {
15
+ console.log(response.data);
16
+ })["catch"](function (error) {
17
+ console.error(error);
18
+ });
@@ -0,0 +1,6 @@
1
+ declare namespace options {
2
+ const method: string;
3
+ const headers: {
4
+ 'content-type': string;
5
+ };
6
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ var options = { method: 'POST', headers: { 'content-type': 'application/json' } };
3
+ fetch('https://httpbin.org/anything', options)
4
+ .then(function (response) { return response.json(); })
5
+ .then(function (response) { return console.log(response); })["catch"](function (err) { return console.error(err); });
@@ -0,0 +1,9 @@
1
+ declare namespace settings {
2
+ const async: boolean;
3
+ const crossDomain: boolean;
4
+ const url: string;
5
+ const method: string;
6
+ const headers: {
7
+ 'content-type': string;
8
+ };
9
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ var settings = {
3
+ async: true,
4
+ crossDomain: true,
5
+ url: 'https://httpbin.org/anything',
6
+ method: 'POST',
7
+ headers: {
8
+ 'content-type': 'application/json'
9
+ }
10
+ };
11
+ $.ajax(settings).done(function (response) {
12
+ console.log(response);
13
+ });
@@ -0,0 +1,2 @@
1
+ declare const data: null;
2
+ declare const xhr: any;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var data = null;
3
+ var xhr = new XMLHttpRequest();
4
+ xhr.withCredentials = true;
5
+ xhr.addEventListener('readystatechange', function () {
6
+ if (this.readyState === this.DONE) {
7
+ console.log(this.responseText);
8
+ }
9
+ });
10
+ xhr.open('POST', 'https://httpbin.org/anything');
11
+ xhr.setRequestHeader('content-type', 'application/json');
12
+ xhr.send(data);
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var axios = require('axios')["default"];
3
+ var options = {
4
+ method: 'POST',
5
+ url: 'https://httpbin.org/anything',
6
+ headers: { 'content-type': 'application/json' }
7
+ };
8
+ axios
9
+ .request(options)
10
+ .then(function (response) {
11
+ console.log(response.data);
12
+ })["catch"](function (error) {
13
+ console.error(error);
14
+ });
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ var fetch = require('node-fetch');
3
+ var url = 'https://httpbin.org/anything';
4
+ var options = { method: 'POST', headers: { 'content-type': 'application/json' } };
5
+ fetch(url, options)
6
+ .then(function (res) { return res.json(); })
7
+ .then(function (json) { return console.log(json); })["catch"](function (err) { return console.error('error:' + err); });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var http = require('https');
3
+ var options = {
4
+ method: 'POST',
5
+ hostname: 'httpbin.org',
6
+ port: null,
7
+ path: '/anything',
8
+ headers: {
9
+ 'content-type': 'application/json'
10
+ }
11
+ };
12
+ var req = http.request(options, function (res) {
13
+ var chunks = [];
14
+ res.on('data', function (chunk) {
15
+ chunks.push(chunk);
16
+ });
17
+ res.on('end', function () {
18
+ var body = Buffer.concat(chunks);
19
+ console.log(body.toString());
20
+ });
21
+ });
22
+ req.end();
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ var request = require('request');
3
+ var options = {
4
+ method: 'POST',
5
+ url: 'https://httpbin.org/anything',
6
+ headers: { 'content-type': 'application/json' }
7
+ };
8
+ request(options, function (error, response, body) {
9
+ if (error)
10
+ throw new Error(error);
11
+ console.log(body);
12
+ });
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ var unirest = require('unirest');
3
+ var req = unirest('POST', 'https://httpbin.org/anything');
4
+ req.headers({
5
+ 'content-type': 'application/json'
6
+ });
7
+ req.end(function (res) {
8
+ if (res.error)
9
+ throw new Error(res.error);
10
+ console.log(res.body);
11
+ });
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "4.0.3",
2
+ "version": "4.0.4",
3
3
  "name": "@readme/httpsnippet",
4
4
  "description": "HTTP Request snippet generator for *most* languages",
5
5
  "homepage": "https://github.com/readmeio/httpsnippet",