RESTful Routes

What are REST, Routes, CRUD?

Representation State Transfer or REST is a pattern/convention for defining our routes. Routes are the code that listens and receives requests then figures out what to send back. CRUD stands for Create, Read, Update, and Delete. These are the 4 basic functions we have when building an API.

So why do we want any of this? Mostly it’s just about keeping things simple and repeatable when building apps. By following a convention we don’t have to reinvent the wheel every time we make an app and other developers will quickly figure out what’s going on.

The Magnificent 7

REST is made up of 7 standard routes:

NameURLHTTP VerbDescription
Index/teamsGETDisplays a list of all teams
New/teams/newGETDisplays a new team form
Create/teamsPOSTAdds new team to the database then redirects
Show/teams/:idGETShows a particular team
Edit/teams/edit/:idGETShows an edit form for a particular team
Update/teams/:idPUTUpdates a particular team in the database then redirects
Destroy/teams/:idDELETERemoves a particular team from the database then redirects


I’ve now reached a turning point in my web dev course. This morning I started writing code on my first meaty project, YelpCamp.

As the name implies the YelpCamp project is Yelp but for campsites. The idea isn’t to release this as a service that people will actually use. The intent is to combine what I’ve learnt from the past few months and use these skills to make a cohesive project that could be released.

I’m quite excited to have finally reached this point. As much as I’ve enjoyed developing specific skills, the parts of the course I’ve enjoyed so far is the work with a visible output. I have a feeling YelpCamp will be a big learning experience and something I’ll likely look back on as a reference in any future developments I do. A library of learnings if you will.

As with other parts of the course I intend to share my progress and code here as a form of public note-taking. I’ll create a specific public GitHub repo so you can follow along and see how the code changes over time. I expect this part of the course will likely take me about 6-8 weeks and will make up the vast majority of posts here over that time. Exciting!


I’ve worked with JSON data before when I was learning Swift and iOS development. At the time I didn’t really know much of JavaScript or its object syntax. Back then, I made my version of a weather app callClima“. That app pulled down weather information based on your current location using JSON data from a third party API.

Having worked with JavaScript for the past few months JSON seems a lot more obvious now. This morning I made a simple IMDB like web app pulling data from I still don’t know how to deploying these node.js apps to a server somewhere. As soon as I do I’ll update posts like this linking to my work.

It’s amazing to me how easy it is to get something quite functional up and running with node.js. A few NPM packages, access to a good source of data from a third party API and you’re away.

Even finding details on APIs for basically anything is really easy thanks to services like It’s basically just a giant directory of anything and everything you might want to know about publically available APIs.

Learning all this kind of makes me feel like I’m discovering coding superpowers. It’s so easy it feels like cheating.

A battle for the ages

Spaces vs tabs is a hilarious holy war that doesn’t really matter but I do find amusing. Modern text editors normalise differences on a project anyway, but I do love these ideological battles. The video below covers it better than I ever could. Enjoy… btw I’m a spaces man 😉

I made a thing: Aroha generator

So I made another thing. The only reason I’m really even talking about it is because what’s going on in Christchurch is so awful I can hardly bear it. Making new things (even simple things like this) is a good distraction.

So in an effort to cheer myself up I made a web thing that says Aroha (and basically anything else I choose) as many times as I ask it to. I did this in node.js, which I’ve never used before, so this is a good learning experience. I have no idea how to deploy anything in node yet, but once I learn I’ll put it up somewhere.

Obviously this is not something I expect to be used in anyway, but learning new things always puts my mind in a good place. It makes me think about the good things in life like change, growth and the new. Something we all need to be thinking more about, especially in dark times. I’m certainly not a perfect person, but I try hard to be a better one every day. We owe that to ourselves, we owe it to each other.

Aroha Generator in all its glory!

If you’re interested in this very random project, check it out on GitHub. If you feel like escaping for a bit then you’re welcome to add to it, or create your own, or help someone else to create one. Just remember to be kind to one another.


Constantly letting down my variables

As it turns out I’ve been doing everything wrong. Well, maybe not everything, but at the very least I’ve been declaring variables incorrectly.

There are actually three different variable types in JavaScript, var, let, and const. I’ve been using var exclusively and it’s actually bad practice. So what’s the difference between each and which should I be using when?


Where at all possible you should use const. Unsurprisingly const is short for constant and without going into to much detail that means it’s something you know will not change. You won’t be able to use this all the time obviously because a lot of the time you need to vary the content of variables. It’s always good pratice to minimise mutability in your code and const is the ultimate example of that.


This is how most of your variables should be declared the majority of the time. The strength of let variables is their scope is limited to the block level. For example:

let numberOfPowers = 1;

if (numberOfPowers === 1) {
  let numberOfPowers = "1 more power than Batman"


In this example we have two variables named the same thing, but because we are using let their scope is limited to different parts of the code so they don’t collide. So in the console, we’d see both “1” and “1 more power than Batman”.


This is the option you should use least often and that’s because of its scope. Unlike let, var has a very wide scope. This is either the function it’s inside of, or if it’s declared outside any function, global. Obviously, that’s not ideal because it creates a greater opportunity to have your variables collide, especially as your projects grow in size. So to revisit our example with var instead of let:

var numberOfPowers = 1;

if (numberOfPowers === 1) {
  var numberOfPowers = "1 more power than Batman"


This time the console will only read 2x “1 more power than Batman”. This is because having a global scope means we are writing over a single global variable rather than creating two different variables with different scopes but the same name.

I can see when you’re learning why this concept might be more of an intermediate level concept. Scope can be a bit tricky to get your head around. At the early stages of learning it’s probably better to focus on core concepts rather than nuances like this, but as your skills grow I think this is an important practice to do with variable declaration.


Getting into a flow state is super helpful when you’re trying to get some coding done. Whenever I’m working on a course exercise or side project I find a few things in my daily routine really help focus my mind:

  1. Keeping my desk tidy – It seems silly but a cluttered desk is a cluttered mind for me. Keeping my workspace simple and functional really makes a difference.
  2. Meditation – I’ve dabbled with this for years, but this year I decided to make it a daily habit. I’m not perfect at it, but I’d say I manage to get 10 mins done in 9 out of 10 days. When I miss a day I notice it. I’m currently using Waking up with Sam Harris, which I’ve found very educational too.
  3. Music – Not all music is good for coding, but the right music makes a world of difference to me. I have a few sources I use to block out the world:
    1. Code Radio – Free Code Camp has a live streaming station via YouTube which is specifically for helping developers concentrate.
    2. White Noise – This isn’t technically music, but it’s just as effective at blocking out distraction.
    3. Spotify or Apple Music focus playlists – If you use a streaming service, there are loads of shared playlists for focus, concentration or study that do the job. I suggest using a paid service if you can afford it. Although I don’t come across a lot of ads in the free version of Spotify, they are frequent enough to interrupt my thinking.
  4. Changing location – Most of my best work happens in my home office, but some of my best work is done in a busy café. Sometimes when you’re having a hard time getting your head around a problem the best thing to do is take a break, change location and give it another go. There’s something about a change of scene that can make all the difference.
  5. Eat – If I’m not paying attention I don’t eat. If I don’t eat, I’m not effective at much of anything. I find removing choice helps me to stick to regular patterns of eating. Like with meditation I don’t always get this right but as a general rule, I eat basically the same thing each day at the same time. This makes sure I’m both fed and also taking regular breaks.

Do you have some flow state secrects I haven’t covered?

How to write modern JS

So you’re learning JavaScript (JS), cool. Putting all this effort in, you’ll want to be learning the modern usage of the language right? Time to get strict.

“use strict” is something I recently stumbled across, and it seems like a really important thing to be using. So much so that I’m a bit surprised it hasn’t been mentioned in the course I’m doing. As it turns out, JS is full of legacy thinking. In an effort to keep new versions of the language compatible with older versions, much of this legacy thinking was/is retained. Obviously this limits JavaScripts ability to overcome its past and improve as time goes on.

Evidently, in 2009 a decision was made to start to modernise JS with the release of ECMAScript 5 (ES5). This meant breaking compatibility with older version of JS if you decided that was what you wanted to do. This is where “use strict” comes in. To enable this “modernisation” you include “use strict” at the top of your JS files like this:

"use strict";
// code below this will be implemented the modern way

Since it’s been 10 years since that decision was made, all modern browsers now support ES5. So unless you need to support browsers before the dawn of IE10 then you should be turning strict mode on for all of your JS development.

This of course begs the question, why? Well, aside from staying current with the language, there are also a number of practical benefits:

  1. Modern JS throws errors on things that where previously ignored. This helps you write better, more secure code
  2. It can improve the performance of your code, sometime significantly. Sometimes the code itself is identical and you just get a free performance boost, nice!
  3. It prevents some syntax being use that future version of the language are likely to use. AKA it future proofs your code

So from here on in, I’m going to be using strict mode exclusively and only avoid it when a situation presents itself that I can’t.

As always MDN is a good source of information on both strict and sloppy mode. Now go forth and write strict code!

I made a thing: To-do list

Yep, I made another thing in JavaScript for the course I’m doing. This one’s a bit more basic, but really it’s more of cutting my teeth with jQuery sort of project rather than something anyone would actually use. It’s a very simple todo list app that lets you add and remove items from a simple list. It has no backend so you can’t save your list or anything useful like that, but the front end side of things does the job at this stage.

A simple to-do list app

If you’re interested in the code you can take a look on GitHub. Of course, you can try the app for yourself. If you find anything wrong with it you can submit an issue.

on() click()

Today I learnt the different between the on(“click”) and click() methods in jQuery.

click() only adds listeners for existing elements, so it will completely ignore any dynamically added items. So in the example below only the <li> declared in the html file will be clickable. All of the new <li> elements added to the todo list won’t be clickable:

<!DOCTYPE html>
<html lang="en">

  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" type="text/css" media="screen" href="assets/css/style.css" />
  <link rel="stylesheet" href="" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
  <script src="" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="

  <div id="container">
    <h1>To-Do List</h1>
    <input type="text" name="" id="">
      <li><span>X</span> Go to potions class</li>
      <li><span>X</span> Buy a new broom</li>
      <li><span>X</span> Visit Hagrid</li>
  <script type="text/javascript" src="assets/js/script.js" charset="utf-8"></script>

// check off specific todos by clicking
$( "li" ).click( function () {
  $( this ).toggleClass( "completed" );
} );

// click on x to delete todo item
$( "span" ).click( function ( event ) {
  $( this ).parent().fadeOut( 300, function () {
    $( this ).remove();
  } );
} );

// add new item to todo list on keypress
$( "input[type='text']" ).keypress( function ( event ) {
  if ( event.which === 13 ) {
    var todoItem = $( this ).val();
    $( this ).val( "" );
    $( "ul" ).append( "<li><span>X</span> " + todoItem + "</li>" );
} );

To get around this, instead of using click() we use on(“click”). Unlike click() on(“click”) will add listeners for all potential future elements on the page. This makes all the dynamic content, like the new items in our todo list app, work flawlessly. So the updated code would look like this:

// check off specific todos by clicking
$( "ul" ).on( "click", "li", function () {
  $( this ).toggleClass( "completed" );
} );

// click on x to delete todo item
$( "ul" ).on( "click", "span", function ( event ) {
  $( this ).parent().fadeOut( 300, function () {
    $( this ).remove();
  } );
} );

// add new item to todo list on keypress
$( "input[type='text']" ).keypress( function ( event ) {
  if ( event.which === 13 ) {
    var todoItem = $( this ).val();
    $( this ).val( "" );
    $( "ul" ).append( "<li><span>X</span> " + todoItem + "</li>" );
} );

jQuery has some excellent documentation. So if you need to drill into the specifics of any particular method (like on() or click()) be sure to RTFM.