Skip to main content

Query parameters

Use case

Append query parameters to the URL from a typed object, including arrays and nested values.

Smallest working example

import { createClient } from '@parcely/core'

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

const { data } = await http.get('/search', {
params: { q: 'hello', page: 1, limit: 20 },
})
// Requests: /search?q=hello&page=1&limit=20

Arrays

await http.get('/items', {
params: { ids: [1, 2, 3] },
})
// Requests: /items?ids=1&ids=2&ids=3

Nested objects

await http.get('/filter', {
params: { filter: { status: 'active', role: 'admin' } },
})

Axios equivalent

// axios:
await http.get('/search', { params: { q: 'hello', page: 1 } })

// parcely (identical):
await http.get('/search', { params: { q: 'hello', page: 1 } })

Notes and gotchas

  • params is typed as Record<string, unknown>.
  • null and undefined values are omitted from the query string.
  • Parameters are appended to any query string already present in the url.
  • parcely does not provide a paramsSerializer config option. The built-in serialiser handles all common cases. If you need custom serialisation, build the query string yourself and append it to the URL.