Skip to content

Lab 07 Kaylyn#10

Open
kaylynyuh wants to merge 5 commits intocodefellows-seattle-javascript-401d10:masterfrom
kaylynyuh:master
Open

Lab 07 Kaylyn#10
kaylynyuh wants to merge 5 commits intocodefellows-seattle-javascript-401d10:masterfrom
kaylynyuh:master

Conversation

@kaylynyuh
Copy link
Copy Markdown

No description provided.

Comment thread lib/parse-body.js
req.on('end', function() {
try {
req.body = JSON.parse(req.body);
callback(null, req.body);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaylynyuh great callback pattern - conforms to industry standards

Comment thread server.js
parseBody(req, function(err) {
if (err) return console.error(err);
if(req.body.text){
res.writeHead(200,{'Content-Type': 'text/plain'});
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaylynyuh best practice is to break this statement onto multiple lines - for example:

res.writeHead(200, {
  'Content-Type': 'text/plain'
});

Comment thread server.js
res.end();
} else {
res.writeHead(400);
res.write(cowsay.say({text: 'bad request\ntry: localhost:3000/cowsay?text=howdy'}));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaylynyuh great UX addition by alerting the user of the proper url structure

Comment thread server.js
res.writeHead(200);
res.write(cowsay.say({text: req.url.query.text}));
res.end();
} else if (req.method === 'GET' && req.url.pathname === '/cowsay' && !req.url.query.text) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaylynyuh this can be refactored into a series of if statements and without the inclusion of else or else if statements - we'll talk about this more in the coming days but try using return instead of explicit else or else if statements on your next major piece of functionality that you build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants