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-configuration-and-requests

Client configuration and request lifecycle

The React Native SDK connects application code to Appwrite through one shared Client context and a set of service APIs. The client keeps project, platform, locale, authentication, environment, and optional live-delivery settings together. Each service describes an operation, while the client turns that description into a request and returns a common result or error.

System boundary

The SDK is the application-side boundary for Appwrite API calls. It keeps request context consistent while service methods describe the operation that the application wants to perform.

Client context

The Client in src/client.ts is the shared context for HTTP calls and realtime connections. It holds the API endpoint, platform, project environment, locale, authentication values, and optional push broker settings. Services keep a reference to this client, so later calls use the client’s current context.

Client configuration is mutable. An application can change the active session, environment, or locale on the shared client, and later calls use the new values. An optional push endpoint and stable push client ID provide the connection details needed by the push service. The client also identifies the SDK and the response format expected by Appwrite. Setup order and platform registration are covered in Client setup and platform integration.

References: src/client.ts• L281-304 src/client.ts• L328-573 src/client.ts• L897-927 src/client.ts• L930-943 src/…/push.ts• L204-246

Service boundary

Each service groups related Appwrite capabilities. A service method supplies the operation path, required inputs, payload, and expected response mode. The shared client then applies the common request rules.

This separation gives application code one simple flow: configure one client, create services with that client, and let each service use the shared request context.

ResponsibilityOwning boundary
Endpoint, project, environment, platform, locale, authentication, and live-delivery contextClient
Operation path, required inputs, and operation payloadService method
Headers, body or query encoding, response conversion, and common errorsShared client call

References: src/service.ts• L4-10 src/client.ts• L930-997

Request lifecycle

An application request moves from a service operation to a shared client call. The service supplies operation-specific data, while the client supplies the wire contract used to reach Appwrite.

This diagram shows how an application call becomes a delivered request and then returns as a value or shared error.

flowchart LR
    A[Application] --> B[Service method]
    B --> C[Path and payload]
    C --> D[Shared client context]
    D --> E[Query or body serialization]
    E --> F[Fetch to Appwrite]
    F --> G[Parsed result]
    F --> H[AppwriteException]

Endpoint assembly

A service combines the configured endpoint with an operation path. It places resource identifiers in that path and puts operation values in the request payload. Required values are checked before transport, so invalid service input fails at the service boundary.

The client exposes encodePath for safe path segments. It URL-encodes identifiers and rejects . and .., which prevents a path value from changing the intended resource path.

Read operations send payload values as URL query parameters. Write operations send structured values in a body. This lets one client support list reads, resource changes, and actions across different HTTP methods.

References: src/client.ts• L273-279 src/client.ts• L930-997 src/service.ts• L13-25

Shared request context

The client merges its SDK and authentication headers with headers supplied by the service. It adds an origin that identifies the React Native platform. Service methods include the configured project in their request headers, while the configured environment selects the project environment when one is in use.

The client can carry session, bearer token, JWT, developer key, cookie, locale, environment, and user impersonation context. Requests include credentials for cookie-based session use. Header details and failure behavior are covered in Request transport and error handling.

ContextEffect on the request
ProjectRoutes the operation to an Appwrite project
EnvironmentSelects the project environment for supported Appwrite Cloud projects
PlatformIdentifies the React Native application origin
Session or cookieCarries user session context
Bearer token or JWTCarries token-based authentication context
Developer keyCarries explicit developer authorization
LocaleSelects the requested locale for supported responses
Impersonation valueRequests an operation in the context of a selected user

References: src/client.ts• L298-304 src/client.ts• L328-573 src/client.ts• L937-957

Payload serialization

The client selects a wire form from the HTTP method and content type. GET values become URL parameters. JSON operations become a JSON body. File operations use multipart form data so metadata and file content travel in one request.

Service.flatten changes nested values into bracketed keys before query encoding. Arrays become repeated bracketed fields. Service file helpers provide byte data for file parts when an upload needs data that the React Native network layer can read. The SDK uses a large-number-aware JSON parser and serializer so supported values do not lose precision during request or response conversion.

References: src/client.ts• L1-46 src/client.ts• L225-251 src/client.ts• L937-997 src/service.ts• L13-48

Network delivery

The shared client delivers the assembled request through React Native’s fetch surface. Ordinary HTTP calls do not add a separate queue or retry layer, so the returned promise represents the Appwrite exchange or its first described failure.

File uploads can add a service-level transfer flow for files larger than one multipart request. The Storage service sends byte ranges as separate requests and keeps the upload identity across those parts. The broader transport behavior is covered in Request transport and error handling.

References: src/client.ts• L1000-1077 src/service.ts• L4-5

Response and failure contract

The shared client gives service callers one result boundary for Appwrite responses. It converts structured data, preserves binary data when requested, and turns failed exchanges into AppwriteException values.

Response conversion

JSON responses become JavaScript values. A service that requests an array buffer receives binary data. Other non-JSON bodies become message objects, which gives callers a readable result when Appwrite does not return JSON.

The client also stores fallback cookies when Appwrite returns them in a browser-capable runtime. Structured results receive a JSON-backed string form, while Appwrite warning headers are sent to the console without changing the result. The client module also provides model-default support so modeled values can receive missing defaults without sharing mutable default objects between results.

References: src/client.ts• L1-119 src/client.ts• L1000-1069

Error boundary

An Appwrite response with status 400 or higher becomes an AppwriteException. The error carries the message, status code, server error type, and response text. Network and response-processing failures are wrapped in the same type, while an existing AppwriteException passes through unchanged.

Application code can handle service failures at one boundary and inspect message, code, type, and response without needing to identify whether the failure came from Appwrite or the local transport path.

References: src/client.ts• L254-270 src/client.ts• L1000-1077

Realtime relationship

Realtime uses the client’s project, environment, endpoint, platform, and session context through a WebSocket channel rather than the ordinary HTTP path. The same client state therefore affects both service calls and live event connections.

The realtime endpoint is derived from the main endpoint unless an explicit WebSocket endpoint is set. Subscriptions start the connection, and the client sends authentication and subscription messages after the socket reports that it is connected.

References: src/client.ts• L328-370 src/client.ts• L575-870 src/client.ts• L872-927

Change checklist

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

  • If client configuration keys or header names change, check service project and environment headers, HTTP authentication, realtime authentication, and push authentication together.
  • If endpoint handling changes, check service URL construction, WebSocket endpoint derivation, and push broker selection.
  • If path encoding rules change, check every service resource path and preserve rejection of . and .. path segments.
  • If a service changes content type or response mode, check the matching serializer and returned value type.
  • If nested or array payload rules change, check both GET query encoding and multipart field encoding.
  • If file-part construction changes, check both React Native fetch inputs and chunked upload behavior.
  • If model defaults change, check response shape compatibility and ensure default objects and arrays are not shared between results.
  • If error fields or status handling change, preserve the shared AppwriteException contract.
  • If session or environment updates change, check cookie fallback behavior, realtime authentication, and push credential selection.
  • If push client identity changes, check broker replay behavior across app restarts.

Important failure modes

TriggerConsequenceGuard
The client has no project IDProject-scoped requests lack valid project context, and realtime cannot create a valid project connectionSet the project before using services or realtime
A service omits a required inputThe call fails before transport and no HTTP request is sentSupply all required service parameters
A path value is not encodedIDs with reserved URL characters can address the wrong resourceUse encodePath for resource IDs
A path value is . or ..The client rejects the call instead of allowing an unsafe path segmentUse a valid resource ID
A multipart request keeps a fixed content type boundaryAppwrite may not parse the file form bodyLet the runtime set the multipart boundary
A file part does not provide readable bytesA React Native upload path cannot construct the file bodyKeep the file part’s URI and byte reader valid for the active fetch runtime
A binary service uses the normal response modeThe caller receives text or a message object instead of binary dataKeep the service response mode aligned with transport
A request returns status 400 or higherThe service promise rejects with AppwriteExceptionHandle the shared error fields at the application boundary
HTTP and realtime endpoints use different configuration rulesCalls and subscriptions can reach different or invalid server addressesKeep endpoint override and derived WebSocket behavior aligned
A project environment is set for only one channelHTTP calls and realtime subscriptions can address different project environmentsApply environment configuration consistently before creating services or subscriptions
The push endpoint or client ID is invalid or unstablePush connections can use the wrong broker or fail to resume its replay cursorUse a valid push endpoint and a stable client ID when replay across restarts is required

Key files

FileWhy to read it
src/client.tsDefines client state, path safety, request assembly, serialization, response conversion, error handling, model defaults, and realtime context
src/service.tsDefines the shared service contract, query flattening, and file-part helpers used by transport
src/index.tsShows the public client and service exports used by React Native applications
src/…/account.tsShows a typical authenticated service operation from input checks to an Appwrite call
src/…/databases.tsShows list and record operations that use paths, queries, and JSON payloads
src/…/storage.tsShows multipart file transfer and binary response paths that depend on shared transport
src/…/realtime.tsShows how client project, endpoint, platform, environment, and session context reaches the WebSocket channel
src/…/push.tsShows how the client’s push endpoint and client ID support broker connection and replay behavior