Auxx.ai

HTTP Requests

Make HTTP requests to external services from your Auxx app's server code.

The server SDK provides a fetch function for making HTTP requests from your app's server code. Import from @auxx/sdk/server.

src/my-action.server.ts
import { fetch } from '@auxx/sdk/server'

const response = await fetch({
  method: 'GET',
  url: 'https://api.example.com/users',
  headers: {
    Authorization: 'Bearer my-token',
  },
})

console.log(response.status) // 200
console.log(response.data)   // parsed response body

Options

interface FetchOptions {
  method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
  url: string
  headers?: Record<string, string>
  body?: any
  timeout?: number
}
PropertyTypeDescription
methodstringHTTP method
urlstringFull URL to request
headersRecord<string, string>?Request headers
bodyany?Request body (auto-serialized to JSON)
timeoutnumber?Request timeout in ms

Response

interface FetchResponse<T = any> {
  status: number
  headers: Record<string, string>
  data: T
}
FieldTypeDescription
statusnumberHTTP status code
headersRecord<string, string>Response headers
dataTParsed response body

POST with body

src/create-contact.server.ts
import { fetch } from '@auxx/sdk/server'

const response = await fetch({
  method: 'POST',
  url: 'https://api.example.com/contacts',
  headers: {
    'Content-Type': 'application/json',
  },
  body: {
    name: 'Jane Doe',
    email: '[email protected]',
  },
})

With connection token

Combine with the connections API to use stored OAuth tokens:

src/sync.server.ts
import { fetch } from '@auxx/sdk/server'
import { getOrganizationConnection } from '@auxx/sdk/server'

const connection = getOrganizationConnection()

const response = await fetch({
  method: 'GET',
  url: 'https://api.hubspot.com/crm/v3/contacts',
  headers: {
    Authorization: `Bearer ${connection.value}`,
  },
})