RESTful Routes (Phew!)

Amelia Haba
2 min readApr 19, 2021

When writing RESTful routes, you should feel just that, restful.

RESTful routes provide a convention for developers. It is essentially the design pattern for programmers to manipulate data and make it nicer for users to interact with.

RESTful routes provide the mapping between the get, post, delete, and patch verbs (HTTP verbs) and the CRUD (create, read, update, delete) actions in the controller.

RESTful Steps:

  1. The application will receive an HTTP request
  2. It takes that request and identifies the HTTP method and the HTTP URL
  3. It then connects the controller action that has that specific method and URL, executes that code accordingly, and determines what response to send back to the user

There are 5 different routes that can be taken.

  1. Index Action: Allows the user to view all of the data or information
  2. New Action: Allows the user to create something new and then save it
  3. Show Action: Allows the user to view one single piece of information
  4. Edit Action: Allows the user to edit something on the application and then save it
  5. Delete Action: Deletes the information
RESTful Routes Outline

The above screenshot is a great reference to use while writing RESTful routes. It shows the HTTP verb, the route, the action, and what it’s used for. This is an example that shows how to manipulate different articles on an application.

A closer look:

Snapshot of my code

In my Sinatra project, I had a program where a user had many characters. In the screenshot above, I am using the new action in RESTful routes. The first controller action is the GET request to load the new.erb form in characters. The second action is the create action that responds to a POST request. This request creates a new character based on the params from the form. Once a new character is created, it redirects to the character page and adds the new character.

RESTful routes make programming easier for the developer and using an application smoother for the user. It’s important to understand what RESTful routes do and how they can transform an application into a seamless, user-friendly experience.

--

--