Using Fetch
React Native provides the Fetch API for your networking needs. Fetch will seem familiar if you have usedXMLHttpRequest or other networking APIs before. You may refer to MDN’s guide on Using Fetch for additional information.
Making requests
In order to fetch content from an arbitrary URL, you can pass the URL to fetch:Handling the response
The above examples show how you can make a request. In many cases, you will want to do something with the response. Networking is an inherently asynchronous operation. Fetch method will return a Promise that makes it straightforward to write code that works in an asynchronous manner:async / await syntax in a React Native app:
fetch, otherwise they will be dropped silently.
Using Other Networking Libraries
The XMLHttpRequest API is built into React Native. This means that you can use third party libraries such as frisbee or axios that depend on it, or you can use the XMLHttpRequest API directly if you prefer.WebSocket Support
React Native also supports WebSockets, a protocol which provides full-duplex communication channels over a single TCP connection.Known Issues with fetch and cookie based authentication
The following options are currently not working with fetch
redirect:manualcredentials:omit
- Having same name headers on Android will result in only the latest one being present. A temporary solution can be found here: https://github.com/facebook/react-native/issues/18837#issuecomment-398779994.
- Cookie based authentication is currently unstable. You can view some of the issues raised here: https://github.com/facebook/react-native/issues/23185
- As a minimum on iOS, when redirected through a
302, if aSet-Cookieheader is present, the cookie is not set properly. Since the redirect cannot be handled manually this might cause a scenario where infinite requests occur if the redirect is the result of an expired session.
Configuring NSURLSession on iOS
For some applications it may be appropriate to provide a customNSURLSessionConfiguration for the underlying NSURLSession that is used for network requests in a React Native application running on iOS. For instance, one may need to set a custom user agent string for all network requests coming from the app or supply NSURLSession with an ephemeral NSURLSessionConfiguration. The function RCTSetCustomNSURLSessionConfigurationProvider allows for such customization. Remember to add the following import to the file in which RCTSetCustomNSURLSessionConfigurationProvider will be called:
RCTSetCustomNSURLSessionConfigurationProvider should be called early in the application life cycle such that it is readily available when needed by React, for instance:

