Skip to main content
React Native provides the Fetch API for making HTTP requests. It follows the web standard Fetch API specification.

Overview

The Fetch API provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline, such as requests and responses. It also provides a global fetch() method that provides an easy, logical way to fetch resources asynchronously across the network.

Global Objects

React Native exposes the following global objects from the Fetch API:
  • fetch - Method for making network requests
  • Headers - Constructor for creating HTTP headers
  • Request - Constructor for creating request objects
  • Response - Constructor for creating response objects

fetch()

Makes an HTTP request and returns a Promise that resolves to a Response object.
string
required
The URL to send the request to
object
Optional configuration for the request
string
default:"GET"
HTTP method: GET, POST, PUT, DELETE, PATCH, etc.
object | Headers
HTTP headers to include in the request
string | FormData | Blob
Request body. Not used for GET or HEAD requests.
string
Request mode: cors, no-cors, same-origin
string
Credentials mode: omit, same-origin, include
string
Cache mode: default, no-store, reload, no-cache, force-cache, only-if-cached
string
Redirect mode: follow, error, manual
string
Referrer URL
AbortSignal
AbortSignal to cancel the request
Returns: Promise<Response> - Resolves to a Response object

Response Object

The Response object represents the response to a request.

Properties

boolean
true if status is in the range 200-299
number
HTTP status code (e.g., 200, 404, 500)
string
Status message corresponding to the status code
Headers
Headers object containing response headers
string
URL of the response
string
Type of response: basic, cors, error, opaque

Methods

function
Parses the response body as JSONReturns: Promise<any>
function
Reads the response body as textReturns: Promise<string>
function
Reads the response body as a BlobReturns: Promise<Blob>
function
Parses the response body as FormDataReturns: Promise<FormData>
function
Reads the response body as an ArrayBufferReturns: Promise<ArrayBuffer>

Examples

Basic GET Request

GET with async/await

POST Request with JSON

Handling Different Status Codes

Upload File with FormData

Request with Custom Headers

Timeout with AbortController

PUT Request

DELETE Request

React Hook for Fetching Data

Notes

  • Fetch is based on the whatwg-fetch polyfill
  • Does not reject on HTTP error status (404, 500, etc.) - check response.ok or response.status
  • CORS policies apply when making requests to different domains
  • iOS requires HTTPS by default (configure App Transport Security to allow HTTP)
  • Consider using libraries like axios for more features (interceptors, automatic retries, etc.)
  • Always handle errors appropriately
  • Be mindful of network conditions on mobile devices