Getting RESTful.

Natasha Avancini
4 min readJan 11, 2021

--

For phase two of my Flatiron course, our focus shifted to Sinatra and understanding the Web. As a daily web user, I admittedly never thought twice about the words and numbers at the end of the URL, trusting that the magic that was the Internet would take me to where I needed to go, usually without fail. It wasn’t until I got further into my studies, and then ultimately had to create my own web application, that I learned the significance of the gibberish at the end of a web address.

The first thing to note is that everything has purpose — I know, I know, that’s obvious. But when you think of the grand scheme of things, and how you get from point A to point B on a website, there was someone who sat there and created the logic to get you there. Having now been in that seat, the reality that “These things don’t exist until you make them exist” was an eye opener.

Making Things Exist

First, some vocab:

A Route is code that is responsible for listening and receiving requests, ultimately deciding what to send back.

CRUD is a way to provide four basic steps of functionality. Create, Read, Update, and Delete resources.

A REST (i.e. Representation State Transfer) route is a convention for defining our routes and a way of mapping HTTP routes with CRUD functionalities.

The whole idea behind RESTful routes, and CRUD, is this: The user(that’s you) wants to sign up to a social media platform. Thankfully, the creators of that platform have added a button that, when you press it, takes you to the sign up page. To the layman, that just means a two second wait and then you can supply your credentials. To the creator, that’s establishing a GET route.

So while it may simply take you to “https://platform.com/signup” which then renders the page. What the button really does underneath the hood is it’s calling the controller, matching up the request with what is defined, taking you to the View (another file that has all of the HTML and Forms you need)file, and then sending it back to the user.

Once the user has filled in their credentials and hit the submit button, they’ll probably be redirected to their profile so they can begin filling out their page. But, once again, another request is sent to the server, the controller handles that request (in this case, POST), communicates with the model, relays the information from the user so that it can create (CRUD) a new User ID, save it, and then redirect them to the desired page. All of this is happening within a few seconds; pretty sweet.

Each action, the user takes to navigate through a website has been meticulously thought out and coded so that the time spent using the platform is simple and easy. There is always a request to be retrieved, read, and a corresponding view to be sent back to the user. If you’ve tried typing in a random route in the URL of whatever platform you’re on, you’ll either be redirected, break something, or find nothing (assuming the devs were actually meticulous). That’s because they most likely accounted for it, or simply didn’t create the route. Nothing exists until you make it so.

The 7 RESTful routes:

Now, that’s great. But how are you supposed to know what routes to do first, how to order them, etc? You already have the basis for what your routes need to do, now you just need to put yourself in the users shoes. What’s the first thing you want to see when you go to a website? What do you want to do from there, etc. This line of thinking will help you create organic routes that make sense and cover every possible page you want for your program.

  • An important note is that when establishing routes, you need to make sure your Static Routes come before your Dynamic Routes. The picture on the left shows 2 GET routes, but the way to figure out how they should be ordered is that any route that isn’t being updated or changed needs to be above those that are, otherwise your routes won’t work. In this case, the GET on line 24 is simply a route that shows the user a specific pet, while the PATCH on line 32 is the route that will update a specific pet.

When creating your own web application, RESTful routes and CRUD are necessary conventions to make things work, and your code easy to read and navigate. No matter what you want your application to be, the User needs to be at the forefront of your design. The really cool thing about creating a web app is that piece by piece you get to watch the fruits of your labor build up, mostly in real time. With every refresh you can see something cool happening, each new route meaning a new page you get to fill out and design. Whether you’re a dev just getting into it, or a curious reader who wants to know more about the process, I hope this helps!

--

--

Natasha Avancini
Natasha Avancini

Written by Natasha Avancini

0 Followers

Lentil soup devouring, casual game playing, one pup loving

No responses yet