Skip to main content

Browser usage

Use case

Use parcely in a web application (React, Vue, Svelte, vanilla JS, etc.).

Smallest working example

import { createClient } from '@parcely/core'

const http = createClient({
baseURL: 'https://api.example.com',
timeout: 10000,
})

const { data } = await http.get('/users/me')

parcely works in any browser with globalThis.fetch (all modern browsers).

CORS considerations

When making requests to a different origin, standard CORS rules apply. The browser enforces these at the fetch level. parcely does not add any CORS-related headers automatically.

If you need to send cookies cross-origin, use a request interceptor:

http.interceptors.request.use((config) => ({
...config,
// Note: this is conceptual -- parcely passes config through to fetch.
// For credentials, handle at the fetch level via interceptors.
}))

Tree-shaking

parcely is tree-shakeable (sideEffects: false, named exports only). Bundlers like Webpack, Rollup, esbuild, and Vite will drop unused code paths (e.g., TLS resolution and Node-specific imports are eliminated in browser bundles).

Axios equivalent

// axios:
import axios from 'axios'
const http = axios.create({ baseURL: 'https://api.example.com' })

// parcely (same pattern):
import { createClient } from '@parcely/core'
const http2 = createClient({ baseURL: 'https://api.example.com' })

Notes and gotchas

  • Upload progress on Safari and Firefox is limited to a terminal callback (see Upload progress).
  • Download progress works in all browsers.
  • The tls option is ignored in browsers (with a one-shot console.warn).
  • parcely does not provide withCredentials or XSRF token handling. Use request interceptors for these patterns.