HTTP protocol, create-react-app configuration, and Cookies setting
Data exchanges between different devices require a compatible data format, and the set of rules that defines how the data is transmitted, received, and understood is called a protocol.
HTTP (Hypertext Transfer Protocol) is a stateless and extensible protocol that exchanges resources on a client-server architecture, designed in 1990.
The client and server exchange information through independent request-response messages, as opposed to streams of data. Each message is self-contained and unrelated to previous messages, even if they share the same connection. During this communication, proxies relay and forward information between the client and server, while performing operations such as caching and authentication.

It is extensible, allowing its messages to include custom headers, such as Content-Type for JSON post bodies, as well as new methods and status codes, which enables the addition of new information and functionalities.
It is stateless, meaning that each request doesn't automatically establish a session or create storage data. However, we can create and share session state by using cookies in either the client request or server response headers, which will be included subsequent requests, allowing us to maintain context and current state across multiple HTTP requests.
The structure of HTTPS request and response messages consists of the following components:

For more information on specific request and response details, refer to CORS (Cross-Origin Resource Sharing) documentation.
The Fetch API is built on top of the HTTP protocol, enabling JavaScript to send and receive HTTP requests, check the API section for more.
HTTPS is an extension of HTTP, with the added 'S' standing for security, which encrypts data in transit to provide a secure connection between the client and server.
CREATE-REACT-APP env configuration
Create-React-App is a command-line interface tool that creates a pre-configured ReactJS project.
We can edit the built-in environment variables of the app configuration, by creating an .env file at the root of the project.
Setting cookies in the Client and Server
Introduced in 1994, a cookie is a small piece of text data used to store various types of data during a user session. Any stored data gets parsed into its original type, which can be maintained during multiple sessions depending on its expiration date.
Cookie data is stored and retrieved from a protected area in the file system, rather than from RAM. On desktop devices, the text data is stored in a SQLite file. In contrast, on mobile devices, cookie data is sandboxed, meaning it is isolated from other apps and stored in a separate area. This sandboxing is a security feature that prevents a single app from accessing data from other apps.
Cookies can originate from both the server and the browser. They can be accessed and edited in the browser using the cookie property of the Document object. The cookie syntax is represented as a string, but is stored as an object in the browser.
The Request and Response headers handle cookies differently. The request's Cookie header automatically includes all browser-stored cookies, while the response's Set-Cookie header includes only the cookies set or updated by the server.
This allows the browser to store session data, such as user state and authentication tokens, enabling stateless HTTP to maintain user context.

When making a fetch request from a browser, if the request either receives a cookie or sends it to the server, the credentials property must be included in the fetch options. This is necessary as the default behavior of the Fetch API is to omit cookies to prevent CSRF attacks. Additionally, the server must also include the credentials property in its CORS options to allow the credentials to be sent and received.
On the server side, cookies can be set using either the res.cookie() method or the Set-Cookie header, but only the Set-Cookie header makes the cookie visible in the document.cookie property.
The httpOnly property makes the cookie inaccesible from the javascript. The expire and max-age serve the same purpose. The domain and path properties define the scope of the cookie. The same-site property will send the cookie response depending on the origin of the request. if set to "none" it needs the "secure" flag so that it's only sent to a secure channel (HTTPS)
On google you can find the cookies in the application> cookies, while in firefox in archiviation> cookies.

1
Last updated