Skip to content

Code Generation for Javascript Node/JQuery #116

@GarryLowther

Description

@GarryLowther

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 ;-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions