Introduction 💻

What does it mean to be a full-stack developer? Well, according to W3Schools, it means: “a person who can develop both client and server software”.

While I do agree with their definition, I would add that full-stack developers are basically match-makers 🥰. On their own, the frontend and backend are independent and don’t necessarily care about each other. Thus, it is the full-stack developer’s responsibility to make that connection happen and “match them up”. In other words, I believe that full-stack developers are people who know how to send and handle data from the frontend to the backend (and vice versa).

With a JavaScript frontend and a Rails backend, the way to make this connection is through fetch requests and controller actions. To further understand how they work together, read on!

Refresher on Fetch Requests 🤔🧐🤨

(Think you have a good handle on fetch requests? Skip to the next section!)

“What is fetch?” from the movie Mean Girls

…Not quite 😅

Fetch requests are a huge part of request/response cycles, especially for sending data. With fetch requests we can “get” or “show” information, “post” new information, “patch” (or update) information, and “destroy” information. The basic syntax is as follows (from MDN):

fetch('http://example.com/movies.json')
.then(response => response.json())
.then(data => console.log(data));

#ruby-on-rails #javascript #guides-and-tutorials #full-stack #code-newbie

Fetch Requests and Controller Actions: Connecting the Frontend to the Backend
1.85 GEEK