...

/

Introduction to Talking to the Server

Introduction to Talking to the Server

Here's a quick introduction to server communication!

We'll cover the following...

Communicating with the server is an important part of client-side apps. The server is usually the source of data truth, and it has information the client needs. For example, server information may have changed, or we may need updated data to draw a new part of the client application. The server also often needs to be informed of actions taken on the client.

In this chapter, we’re going to look at two basic ways of communicating with the server: making asynchronous Ajax calls and using WebSockets via the Rails ActionCable library. On the Stimulus page in our sample app, we’re going to get information from the server about which concerts are sold out. On the React page, we’re going to send and receive data about which seats in the concert have already been held.

However, before we dive into more complication of getting information from the server, I want to mention a quick and cheap technique that is sometimes exactly what you need: the Gon gem, which is a tool that allows your Rails server-side to set up arbitrary global data visible to your JavaScript client side.

Cheating

...