Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Generation for Javascript Node/JQuery #116

Closed
GarryLowther opened this issue Oct 22, 2019 · 0 comments · Fixed by #125
Closed

Code Generation for Javascript Node/JQuery #116

GarryLowther opened this issue Oct 22, 2019 · 0 comments · Fixed by #125

Comments

@GarryLowther
Copy link

Your code generator for Node and JQuery is very good at the top, then tails away, for example at the start, this is good:

var https = require('https');

var options = {
  'method': 'POST',
  'hostname': ....
};

var req = https.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });
...

However, this code is not so good:

var postData =  "{\n\tFieldName: 'data'\n}";
req.write(postData);
req.end();

May I suggest that this last bit uses proper JSON objects rather than strings which are simply yuk!

Even this JQuery code:

var settings = {
  "url": "https://postman.com/security/authenticate",
  "method": "POST",
  ...
  "data": "{\r\n\tFullName: '{{FullName}}',\r\n\tPassword: '{{Password}}'\r\n}"
};

Should be re-written as:

var credentials = {
    FullName: '{{FullName}}',
    Password: '{{Password}}'
};
var sJSON = JSON.stringify(credentials);

var settings = {
  "url": "https://postman.com/security/authenticate",
  "method": "POST",
  ...
  "data": sJSON
};

Much easier to read, agree?

Everything else is coming along nicely ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant