RESTful Routing in React/Rails

Luis Dejesus Castro
2 min readJul 13, 2021

When developing a React/Rails application, it is important to always consider the perspective of the users who will be using your app, as well as the developers who will be working on the app. Let’s say you are creating an application and you’ve got your entire app planned out as far as functionality but there’s one thing missing; your routes. This is where we encounter the challenge: how do you approach naming your routes in a way that will make sense to the user and an engineer? For this problem, there is an industry-standard convention known as REST.

REST stands for Representational State Transfer and when following the guidelines of REST, you gain the ability to create RESTful routes. The goal of RESTful routing is to allow us to create routes using conventional naming patterns which in turn describe a relationship between the HTTP requests sent from your front-end(GET, POST, PATCH, DELETE) and your CRUD actions receiving those requests and handling them in your back-end (Create, Read, Update, Destroy). As shown below, each route name and path corresponds to a different HTTP method which then has its own specific purpose:

The front-end sends a (fetch) request to the back-end using a URL path and an HTTP method. That request is then read by the back-end and matched to the proper route name which corresponds to a controller action in our object controller. To view your routes in your terminal you can use the command:

rails routes

This will allow you to see a list of all the routes available to you in the routes.rb file in your config folder.

--

--