Introducing a new way to review your PRs.

Read the announcement

appwrite / sdk-for-react-native

[READ ONLY] Official Appwrite React Native SDK 💙 ⚛︎

View on GitHub

24 documents · Updated Nov 18, 2026

docs / client-setup-and-platform-integration

Client setup and platform integration

The Client is the shared connection context for the React Native SDK. It identifies the Appwrite endpoint and project, carries user and locale context, and supplies platform details for HTTP calls and realtime connections. This page is a child of Client configuration and request lifecycle; the shared request path is described in Request transport and error handling.

Client configuration

Client configuration gives each service the information needed to address one Appwrite project. The configuration stays on the shared client, so services that use it follow the client’s current values.

Endpoint and project identity

The API endpoint is the base address for HTTP calls. The project ID selects the Appwrite project at that address. A new client uses https://cloud.appwrite.io/v1 by default, but it has no project ID, so consumers must set the project before project-scoped calls.

The client derives a WebSocket endpoint from the HTTP endpoint. Consumers can replace that value when the realtime server uses a different address. Push integrations can use a separate broker endpoint and a stable client ID when the push service needs offline replay across app restarts. The platform value identifies the application in request and socket metadata, so it should match the platform registered for the project. The SDK targets Appwrite server 2.6.x as shipped on Appwrite Cloud; a self-hosted server on an older release may need a matching older SDK.

SettingRoleConsumer action
EndpointBase address for HTTP callsKeep the cloud default or set the self-hosted API URL
Realtime endpointWebSocket address for subscriptions and presenceOverride it only when the derived address is not correct
Push endpointMQTT broker address for push connectionsSet it when the push service uses a broker different from its default
Push client IDStable identity for push replaySet a stable value when replay must continue across app restarts
ProjectAppwrite project identitySet the project ID before using project services
PlatformApplication identity in requests and socketsSet the platform value used by the project
EnvironmentOptional project environment identitySet it when the Appwrite project uses environments

References: src/client.ts• L281-345 src/client.ts• L355-409 src/client.ts• L420-437 src/client.ts• L483-497 README.md• L8-10 README.md• L41-54

Session and locale context

The session value identifies the user session for authenticated calls. The locale value selects the requested Appwrite locale. Both values live on the client and become part of the request context, so all services created from that client can share them.

Set these values before a service call when they apply to the whole client. Update the shared client when the active user or locale changes. Realtime uses the configured session when it authenticates a connection.

References: src/client.ts• L470-481 src/client.ts• L499-512 src/client.ts• L751-783

Self-signed certificate trust

The client has no certificate setter and does not bypass certificate checks. HTTP requests use the runtime fetch API, while realtime uses the runtime WebSocket API. Certificate trust therefore belongs to the target device, app runtime, or network layer.

For a self-hosted endpoint, install or trust the certificate authority through the normal mechanism for the target environment. setEndpoint() accepts HTTP and HTTPS URLs, but HTTP does not provide TLS protection.

References: src/client.ts• L328-345 src/client.ts• L937-1003 src/client.ts• L643-665 README.md• L54

React Native integration

The SDK expects the React Native app to provide the platform and network features used by the client. It has no separate bootstrap step, but the app must install the required Expo modules and load the URL polyfill before SDK code runs. Consumers create one client, configure it, and pass it to the services they use.

Runtime dependencies

The package declares the runtime pieces needed by its React Native services. React Native provides platform information and the app network surface. Expo file-system support enables file-aware services, and Expo is a peer runtime for that integration. The app also installs react-native-url-polyfill because the SDK expects URL support before initialization.

Dependency or runtime featurePurpose in the SDK
react-nativeProvides the platform value used in request origins and realtime sockets
expo-file-systemSupports file operations used by file-aware services
expoProvides the Expo runtime expected by the file-system integration
react-native-url-polyfillProvides URL support before SDK code runs in React Native
fetch and WebSocketProvide HTTP and realtime network connections
json-bigintPreserves large numeric values while the client reads and writes JSON

The package supports Expo SDK 52 and later. It supports React Native 0.76.7 through versions below 1.0, and its package tooling requires Node 20 or later. An app must include the runtime dependencies needed by the services it uses. Push services add optional peer dependencies for notifications, background work, and native TCP sockets.

References: package.json• L41-73 package.json• L75-84 src/client.ts• L1-7 src/client.ts• L937-1003 src/client.ts• L619-665 README.md• L14-22 README.md• L33-39 README.md• L170-180

Client initialization

Client initialization has one main order: install the app dependencies, load the URL polyfill, create a client, set its endpoint and project, set its platform, and then create services from it. Add session, locale, or environment values when the app needs them.

The following pattern creates an HTTP service context. The same client can be passed to Account, Storage, Locale, or another exported service.

import 'react-native-url-polyfill/auto';
import { Account, Client } from 'react-native-appwrite';

const client = new Client()
    .setEndpoint('https://<REGION>.cloud.appwrite.io/v1')
    .setProject('<YOUR_PROJECT_ID>')
    .setPlatform('<YOUR_PLATFORM>');

const account = new Account(client);

The package entry point exposes Client and the service classes. Service constructors receive the same client, which keeps endpoint, project, session, locale, environment, and platform context aligned across calls.

References: src/client.ts• L281-512 src/…/account.ts• L12-17 docs/…/get.md• L1-10 README.md• L33-52

Realtime initialization

Realtime needs no separate startup call. A subscription starts the connection with the configured project and realtime endpoint. If no override exists, the client uses the WebSocket address derived from the main endpoint.

The client needs a project ID and a usable platform value before realtime use. An environment value is included when one is configured. After the connection opens, it authenticates with the configured session when one is available and then sends the subscriptions. In web runtimes, it can also use the stored fallback session when the client has no session value.

This diagram shows how setup values move from the client into HTTP services or a realtime connection.

flowchart TD
    A[Create Client] --> B[Set endpoint, project, and platform]
    B --> C[Set session, locale, or environment when needed]
    C --> D[Create service with Client]
    D --> E[HTTP service call]
    C --> F[Create realtime subscription]
    F --> G[Open WebSocket for project and environment]
    G --> H[Authenticate session and register subscription]

References: src/client.ts• L619-701 src/client.ts• L751-783 src/client.ts• L897-927 src/…/realtime.ts• L194-220

Change checklist

When these files or sections are changed, remember to consider these:

  • If endpoint, project, or environment configuration changes, check both HTTP service URLs and the realtime project connection.
  • If platform metadata changes, check both the HTTP Origin header and native versus web WebSocket construction.
  • If session handling changes, check both HTTP authentication context and realtime authentication after the connection handshake.
  • If push endpoint or client identity changes, check broker connection setup and offline replay behavior.
  • If file-service imports change, keep the package dependency and Expo peer-dependency contract aligned.
  • If URL support or app startup guidance changes, keep the required polyfill install and import order aligned with client initialization.
  • If the package entry point changes, keep the public Client and service exports aligned with the initialization pattern.

Important failure modes

TriggerConsequenceGuard
The endpoint does not start with http:// or https://Client setup throws before it stores the endpointUse a complete HTTP or HTTPS URL
The project ID is missingProject-scoped calls lack the project header, and realtime cannot open a valid project connectionSet the project before using services
A realtime override does not use ws:// or wss://Realtime endpoint setup throwsUse a valid WebSocket URL
The URL polyfill is not loaded before SDK codeReact Native setup can fail when the SDK needs URL supportImport react-native-url-polyfill/auto in the app entry file first
A self-signed certificate is not trusted by the target runtimeHTTP or WebSocket connection fails outside the SDK request pathConfigure certificate trust on the device or in the app runtime
The platform value does not match the project setupRequest and socket origin metadata does not identify the expected app platformSet the platform registered with Appwrite
File-aware services run without the required Expo runtime packagesThe app cannot load or run those service pathsInstall the declared React Native and Expo peer packages
An environment is required but is not configuredCalls can reach the wrong project environmentSet the environment together with the project ID

Key files

FileWhy to read it
src/client.tsDefines client defaults, setup values, request metadata, realtime connection state, and push connection settings
src/index.tsShows the public package entry point for Client and service classes
src/…/realtime.tsShows how client project, platform, session, and endpoint settings reach realtime use
src/…/account.tsShows a service receiving the shared client context
src/…/storage.tsShows the file-aware service path that depends on Expo file-system support
README.mdDefines the supported Appwrite and Expo setup path, platform registration, URL polyfill requirement, and client initialization example
package.jsonDefines package entry points, React Native and Expo peer dependencies, and the Node engine requirement