REMEmbering RESTful

Programming is all about leveling up layer’s of abstraction to make your life easier. However, sometimes it’s easier to go a level down so you can better understand the magic you have been given.

Some seemingly stupid ways have helped me remember things from childhood.

Order of operations

Please Excuse My Dear Aunt Sally
Parentheses Exponents Multiply Divide Add Subtract

The planets (no, I don’t know what they did with Pluto).

My Very Educated Mother Just Served Us Nine Pizzas
Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune Pluto

With this in mind and knowing the importance of REST, I’ve come up with a few different ways to remember the seven core actions and their related verbs/uses. Hopefully these can help you as well.

I am Now Sorry for Everything — from God

This is a quick way to remember the four GET functions. Breaking that down, we get:

I am = Index all

get '/pets' do
@pets = Pet.all
erb :'/pets/index'
end

Now = New
  get '/pets/new' do 
erb :'/pets/new'
end

Sorry for = Show find
  get '/pets/:id' do 
@pet = Pet.find(params[:id])
erb :'/pets/show'
end

Everything-from = Edit find
  get '/pets/:id/edit' do
@pet = Pet.find(params[:id])
erb :'pets/edit'
end

God = Get

But there are still three actions left (all the non-gets)

Can cars really prevent Us from using phones During family dinner

Breaking it down again:

Can cars really prevent = Create create redirect post
  post '/pets' do      
@pet = Pet.create(name: params[:name])
redirect to "pets/#{@pet.id}"
end

Us from using phones = Update find update patch
  patch '/pets/:id' do 
pet = Pet.find(params[:id])
pet.update(name: params[:pet][:name])
redirect to "pets/#{pet.id}"
end

During family dinner = Delete find destroy
  delete '/pets/:id/delete' do
pet = Pet.find(params[:id])
pet.destroy
"#{pet.name} was deleted"
end

Furthermore, for any Game of Thrones fans, there is at times a strong similarity between the seven actions and the Faith of the Seven #nospoilers

  • The Crone: represents wisdom and foresight. She is represented carrying a lantern.
  • Index — what is more wise than the entire database?
  • The Warrior: represents strength and courage in battle.
  • Destroy — don’t really need to explain
  • The Smith: represents creation and craftsmanship.
  • Create — creation is in the name, people
  • The Stranger: The Stranger represents death and the unknown. It is rarely prayed to.
  • New — by defintion the stranger is new
  • The Maiden: represents purity, innocence, love, and beauty.
  • Show — the beauty of the individual
  • The Mother: represents mercy, peace, fertility, and childbirth. She is sometimes referred to as “the strength of women”.
  • Edit — linked together with update
  • The Father: represents divine justice, and judges the souls of the dead.
  • Update
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.