# DAVClient & createDAVClient > Class-based DAVClient and functional createDAVClient entry points, options, authentication methods, and method list. `tsdav` provides two ways to create a pre-configured client that shares `serverUrl`, authentication, discovered `account`, `fetchOptions`, and custom `fetch` across requests: - **`DAVClient`** — class-based API. Call `await client.login()` once before calling account-dependent helpers. - **`createDAVClient`** — async factory that resolves auth headers and (when `defaultAccountType` is set) runs account discovery immediately, returning bound helper methods. ## Constructor / Factory Options Both `new DAVClient(params)` and `await createDAVClient(params)` accept the same parameter object: ```ts type DAVClientParams = { serverUrl: string; credentials: DAVCredentials; authMethod?: 'Basic' | 'Oauth' | 'Digest' | 'Custom' | 'Bearer'; authFunction?: (credentials: DAVCredentials) => Promise>; defaultAccountType?: 'caldav' | 'carddav'; fetchOptions?: RequestInit; fetch?: typeof globalThis.fetch; }; ``` - `serverUrl` **required** — Base DAV server URL (for example `https://caldav.icloud.com` or `https://example.com/dav.php/`). - `credentials` **required** — [DAVCredentials](/types/davcredentials/) object matching your `authMethod`. - `authMethod` — Defaults to `'Basic'`. - `'Basic'`: Sends HTTP Basic credentials. Automatically upgrades to HTTP Digest if the server answers with a Digest-only `401` challenge and WebCrypto is available. - `'Digest'`: Performs RFC 7616 HTTP Digest challenge-response per request (or sends legacy `credentials.digestString` as-is). See [Digest authentication](/helpers/authhelpers/#digest-authentication). - `'Oauth'`: Resolves and refreshes OAuth 2.0 Bearer tokens via `getOauthHeaders`, sharing one refresh across concurrent requests and mutating `credentials` in place with updated tokens and `expiration`. - `'Bearer'`: Sends `Authorization: Bearer ` directly. - `'Custom'`: Calls `authFunction(credentials)` on authentication to produce request headers. - `authFunction` — Required when `authMethod` is `'Custom'`. - `defaultAccountType` — `'caldav'` or `'carddav'`. - In `DAVClient`, defaults to `'caldav'` and is used by `client.login()`. - In `createDAVClient`, account discovery only runs automatically if `defaultAccountType` is provided. - `fetchOptions` — Default `RequestInit` options forwarded to every request. Client-level `fetchOptions.headers` override default `authHeaders`, while per-call `headers` and per-call `fetchOptions.headers` take precedence over client defaults. - `fetch` — Custom Fetch API implementation (for Electron IPC, proxies, tests, or non-standard runtimes). ## Class-Based API (`DAVClient`) ```ts import { DAVClient } from 'tsdav'; const client = new DAVClient({ serverUrl: 'https://caldav.icloud.com', credentials: { username: 'YOUR_APPLE_ID', password: 'YOUR_APP_SPECIFIC_PASSWORD', }, authMethod: 'Basic', defaultAccountType: 'caldav', }); await client.login(); const calendars = await client.fetchCalendars(); ``` ### `client.login(options?)` Authenticates the client and populates `client.account` via [createAccount](/webdav/account/createaccount/). - `options.loadCollections` — When `true`, discovers calendars or address books during login. - `options.loadObjects` — When `true`, also fetches all objects in each discovered collection (implies `loadCollections`). ### Bound Callbacks `client.calendarMultiGet` and `client.addressBookMultiGet` are bound in the constructor so they can be passed directly as `collection.objectMultiGet` to [smartCollectionSync](/webdav/collection/smartcollectionsync/) / `smartCollectionSyncDetailed`. ## Functional Factory (`createDAVClient`) ```ts import { createDAVClient } from 'tsdav'; const client = await createDAVClient({ serverUrl: 'https://caldav.icloud.com', credentials: { username: 'YOUR_APPLE_ID', password: 'YOUR_APP_SPECIFIC_PASSWORD', }, authMethod: 'Basic', defaultAccountType: 'caldav', }); const calendars = await client.fetchCalendars(); ``` :::note When calling `client.createAccount(...)` on the object returned by `createDAVClient`, pass `account.accountType` explicitly (`'caldav'` or `'carddav'`). ::: ## Available Client Methods Both `DAVClient` instances and the object returned by `createDAVClient` expose all high-level and low-level DAV methods with shared auth, account, `fetchOptions`, and `fetch` defaults: - **WebDAV:** [davRequest](/webdav/davrequest/), [propfind](/webdav/propfind/), [createAccount](/webdav/account/createaccount/), [createObject](/webdav/createobject/), [updateObject](/webdav/updateobject/), [deleteObject](/webdav/deleteobject/) - **Collections:** [makeCollection](/webdav/collection/makecollection/), [collectionQuery](/webdav/collection/collectionquery/), [syncCollection](/webdav/collection/synccollection/), [supportedReportSet](/webdav/collection/supportedreportset/), [isCollectionDirty](/webdav/collection/iscollectiondirty/), [smartCollectionSync](/webdav/collection/smartcollectionsync/), `smartCollectionSyncDetailed` - **CalDAV:** [makeCalendar](/caldav/makecalendar/), [fetchCalendars](/caldav/fetchcalendars/), [fetchCalendarUserAddresses](/caldav/fetchcalendaruseraddresses/), [fetchCalendarObjects](/caldav/fetchcalendarobjects/), [createCalendarObject](/caldav/createcalendarobject/), [updateCalendarObject](/caldav/updatecalendarobject/), [deleteCalendarObject](/caldav/deletecalendarobject/), [calendarQuery](/caldav/calendarquery/), [calendarMultiGet](/caldav/calendarmultiget/), [syncCalendars](/caldav/synccalendars/), `syncCalendarsDetailed`, [freeBusyQuery](/caldav/freebusyquery/) - **CardDAV:** [fetchAddressBooks](/carddav/fetchaddressbooks/), [fetchVCards](/carddav/fetchvcards/), [createVCard](/carddav/createvcard/), [updateVCard](/carddav/updatevcard/), [deleteVCard](/carddav/deletevcard/), [addressBookQuery](/carddav/addressbookquery/), [addressBookMultiGet](/carddav/addressbookmultiget/)