Trigani

Client package

How the client package works

Understanding API Options

1. filter

Filters allow you to refine API responses based on field values. Examples:

const filter = {
  field: { $eq: "foo" },
  field2: { field3: { $inArray: ["foo", "bar"]} },
  $or: [
    { field6: { $gte: new Date() } },
    { field7: { $lt: 6 } }
  ]
}

2. sort

Sorts data based on fields in ascending (asc) or descending (desc) order.

const sort = ["category.name:asc", "name:asc"]

3. populate

Defines related data to be included in the response.

const populate = {
  author: true,
  category: {
    parent: true
  }
}

4. page and pageSize

Defines pagination options.

const options = {
  page: 1,
  pageSize: 10
}

5. formatOptions

Controls rich text formatting.

const formatOptions = { richText: 'html' }

API Methods

1. getRow

Fetches a single record by ID.

const post = await spaceClient.getRow<Post>('posts', 'some-id', { populate: { image: true } })

2. getRows

Fetches multiple records with filtering, sorting, and pagination.

const { data, meta } = await spaceClient.getRows<Post>('posts', {
  filter: { category: { slug: { $eq: 'tech' } } },
  page: 1,
  pageSize: 10,
  populate: { image: true },
  formatOptions: { richText: 'html' }
})

These methods make interacting with the API straightforward and efficient.

On this page