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.
| Setting | Role | Consumer action |
|---|---|---|
| Endpoint | Base address for HTTP calls | Keep the cloud default or set the self-hosted API URL |
| Realtime endpoint | WebSocket address for subscriptions and presence | Override it only when the derived address is not correct |
| Push endpoint | MQTT broker address for push connections | Set it when the push service uses a broker different from its default |
| Push client ID | Stable identity for push replay | Set a stable value when replay must continue across app restarts |
| Project | Appwrite project identity | Set the project ID before using project services |
| Platform | Application identity in requests and sockets | Set the platform value used by the project |
| Environment | Optional project environment identity | Set 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 feature | Purpose in the SDK |
|---|---|
react-native | Provides the platform value used in request origins and realtime sockets |
expo-file-system | Supports file operations used by file-aware services |
expo | Provides the Expo runtime expected by the file-system integration |
react-native-url-polyfill | Provides URL support before SDK code runs in React Native |
fetch and WebSocket | Provide HTTP and realtime network connections |
json-bigint | Preserves 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
Originheader 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
Clientand service exports aligned with the initialization pattern.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
The endpoint does not start with http:// or https:// | Client setup throws before it stores the endpoint | Use a complete HTTP or HTTPS URL |
| The project ID is missing | Project-scoped calls lack the project header, and realtime cannot open a valid project connection | Set the project before using services |
A realtime override does not use ws:// or wss:// | Realtime endpoint setup throws | Use a valid WebSocket URL |
| The URL polyfill is not loaded before SDK code | React Native setup can fail when the SDK needs URL support | Import react-native-url-polyfill/auto in the app entry file first |
| A self-signed certificate is not trusted by the target runtime | HTTP or WebSocket connection fails outside the SDK request path | Configure certificate trust on the device or in the app runtime |
| The platform value does not match the project setup | Request and socket origin metadata does not identify the expected app platform | Set the platform registered with Appwrite |
| File-aware services run without the required Expo runtime packages | The app cannot load or run those service paths | Install the declared React Native and Expo peer packages |
| An environment is required but is not configured | Calls can reach the wrong project environment | Set the environment together with the project ID |
Key files
| File | Why to read it |
|---|---|
| src/client.ts | Defines client defaults, setup values, request metadata, realtime connection state, and push connection settings |
| src/index.ts | Shows the public package entry point for Client and service classes |
| src/…/realtime.ts | Shows how client project, platform, session, and endpoint settings reach realtime use |
| src/…/account.ts | Shows a service receiving the shared client context |
| src/…/storage.ts | Shows the file-aware service path that depends on Expo file-system support |
| README.md | Defines the supported Appwrite and Expo setup path, platform registration, URL polyfill requirement, and client initialization example |
| package.json | Defines package entry points, React Native and Expo peer dependencies, and the Node engine requirement |