Making Code Stick: Day 7

And we’re done… HTTP JSON API SERVER is in the books and I’ve finished learnyounode.

This one took a little longer because life and because I ran a lot of debug code making sure I understood the inputs coming in from the URL parser. Once I was sure of what values I’d get via what properties, the rest fell into line.

The one thing I have to point out is to remember the second argument of “true” when calling url.parse. Without it, you don’t get the lovely object of all the different useful bits.

Also, in my code, I used a switch with the parsed.pathname value from the parsed URL rather than if-then with regular expressions looking for the same values anywhere in the URL. Unless there’s a specific weakness in the pathname output of url.parse(), I’d believe it’s better to use the pathname rather than the regular expression, because the regexp is more likely to hit a false positive.

Last, after the fact, it occurred to me that neither my solution nor the sample solution in the unit contained a test to see if there was a date value being passed in the “iso” query variable or if the value being passed was a valid date. Those we took for granted.

Anyway, here’s my solution that passed.

Leave a Reply

Your email address will not be published. Required fields are marked *