Request/Response Cycle & Thoroughness

Georges Akouri-Shan
3 min readJun 28, 2016

The request/response cycle traces how a user’s request flows through the application but first lets go over how the request is initiated.

  1. Use Chrome
  2. type in a website address
  3. #2 gets sent to a DNS server which really just translates text into an IP address so you can reach your intended server.
  4. The translated request is sent to the intended server and processed accordingly (gets,post, etc).

So now we can break down the actual user interaction with our server (aka request/response cycle).

  1. #1 in this diagram is essentially the steps we discussed above. The user types in www.greatstuff.com and DNS responds with 121.124.123.13.
  2. So now that you can directly contact your intended server, the server will begin to process your request. (Ignore the rails aspect of this image; we’re not yet qualified)
  3. So now our controller processes the request and asks: Is it a get or post? What am I as a controller meant to do with this info being passed to me?

4. So let’s say now that the user needs a new bean bag after his latest stunt(see gif) and heads off to greatstuff.com/beanbag. The Controller should then have code similar to the below:

get '/:item' do
@item = params["item"]
erb :"item_index.html"
end

Here the controller will identify the item from the get request sent to it and then use a template erb file to fill in the details of that item. This process involves the controller speaking with the model where bean bag exists and asking for the details involving said bean bag.

5–7. Then the controller will take that information and render it for the viewer to see. The code could look like this but will more than likely be a bit more complex.

8. This view will then be rendered for the user’s browser in html and the user is then able make another request.

<%= @item.name %>
<%= @item.price %>
<%= @item.details %>

That’s pretty much it; real straightforward with not much mystery..

So now onto my next topic which I decided to bury here so it doesn’t get much exposure. Forms are really basic in their nature as all they do is provide a way for our server to receive information. The more important part is how we process and store that data. I love me a promotion as much as the next guy but I thrive on finding their loopholes and abusing them to death.

Lets take for example this mythical company called Handy. Handy provides cleaning services, handyman services, and so on. They initiate a referral program whereby each person referred gets $35 off their first cleaning and the referring party gets $35 credit for future bookings. What A DEAL!!!!!!! But as y’all guessed its not enough. So let’s break down the process of getting this referral bonus:

  1. Have an account and send a referral to a friend
  2. friend creates an account with name,address,phone,email, and cc.
  3. Handy databases this new user (User.create(name:, address:, etc))
  4. Friend makes a new booking and saves $35 off the booking
  5. You get $35 credit.

Now Handy allows you the flexibility to change your email and phone number because you never know; shit might happen and people are always losing their emails. So if I decide to change my email to asfdasfsafasf@gmail.com and my phone number to 1231231234. I wonder if I can now make a new account with the same details??

You can find the answer in the screenshot below.

Moral of the story: Be thorough with your code or you may cost your company thousands of dollars!

Here’s my referral link which will actually give you $50 off.

handy.com/r/GEORGE6645

--

--