Fetch

Fetch is a modern concept equivalent to XMLHttpRequest . It offers a lot of the same functionality as the XMLHttpRequest , but is designed to be more extensible and efficient. It operates Request and Response objects that can be re-used in the following requests.

In modern browsers, this API is a part of WindowOrWorkerGlobalScope mixin that extends global JavaScript scope, however in older browsers and React Native (in order to not to re-implement a new API for both platforms) it uses GitHub’s whatwg-fetch polyfill that relies on XMLHttpRequest implementation, so it implicitly uses React Native’s Networking module under the hood. That implies some nuances that we need to be aware of. For instance, one of the known Networking issues is impossibility of transferring any binary data over the wire that currently leads to workarounds (like working with base64 representation of binary data) and/or third-party solutions (like react-native-fetch-blob). You can learn more about these and other implications in the second part of my ReactNativeEU talk.

WebSocket

WebSocket is a communications protocol, providing full-duplex communication channels over a single TCP connection.

You might already use WebSockets for developing your React Native applications. Every time you start an app in development mode, it creates a WebSocket connection between packager and the app itself, so every time you edit your JS files (or other static assets), it sends a patch signal to the app so it can react to the changes.

As far as WebSocket is somewhat different from a standalone request, there is a separated module called WebSockets that performs as a back-end for the technology. Not hard to guess, that by analogy with XMLHttpRequest , WebSocket also has two different implementations across operating systems. Android is being consistent using OkHTTP library while iOS uses a self-written implementation on top of NSStream .

Networking issues

The second part of this article is dedicated to cover the most common networking issues in React Native. Debugging network requests, sending binary data over the wire and credentials management — today we’ll unveil them all.