DEV Community

Cover image for Where do these routes go?
Gia Jennings
Gia Jennings

Posted on

Where do these routes go?

Restful Routes

Restful routes map HTTP verbs (get, post, patch, etc.) to CRUD actions (create, read, update, delete). Although each route has its own responsibility, within that block of code are specific lines of code that trigger different actions. Let's dive into this using the routes associated with logging in.

GET ('/login')

Alt Text

Within this route, the user is simply sending a GET request to the '/login' route which loads the login form within the view.

POST ('/login')

Alt Text

Here, the POST request handles the form submission where the information is authenticated, a session is created and the user is redirected to his/her '/runs' page.

Deeper Dive (redirecting vs. erb)

Within these routes, actions are occurring at different points but where and how?

Well the GET request is triggering actions, but it's only responsible for rendering the login page if the user is not successfully logged in or redirecting if the user is logged in. Within this request, an erb command is used because the action only needs to render an erb file for display while the user remains in the current route.

However, it's the POST request that handles the user's form input, authenticating the information, and setting a session id to successfully login the user. Within this request, redirect is used because the state was changed once the input was processed.

This example shows how each route is responsible for different actions based on specific lines of code although they work together for, in this case, a user logging in.

Top comments (0)