Skip to content

Unified Response

Every method across all integrations returns the same HttpResponse<T> shape:

ts
interface HttpResponse<T = any> {
  status: number
  data: T
  headers?: Record<string, any>
}

Consistent Everywhere

No matter which integration you use, the response is identical:

ts
const api = new BaseApi({ token })
const res = await api.get<User[]>('/users')
// res.status  → 200
// res.data    → User[]
// res.headers → { 'content-type': 'application/json', ... }
ts
const api = new PlaywrightApi(context, token)
const res = await api.get<User[]>('/users')
// res.status  → 200
// res.data    → User[]
ts
const api = new SupertestApi(agent, token)
const res = await api.get<User[]>('/users')
// res.status  → 200
// res.data    → User[]
// res.headers → { 'content-type': 'application/json', ... }

Why This Matters

This means your assertion logic doesn't depend on the framework:

ts
// This helper works with ANY integration
function assertSuccess<T>(res: HttpResponse<T>) {
  expect(res.status).toBeGreaterThanOrEqual(200)
  expect(res.status).toBeLessThan(300)
  return res.data
}

const users = assertSuccess(await api.getUsers())

HTTP Methods

All integrations support the same five methods:

MethodSignature
GETget<T>(url, headers?)
POSTpost<T>(url, payload?, headers?)
PUTput<T>(url, payload?, headers?)
DELETEdelete<T>(url, headers?)
HEADhead<T>(url, headers?)

Each returns Promise<HttpResponse<T>>.

Released under the MIT License.