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.
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 bodyOptions
interface FetchOptions {
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
url: string
headers?: Record<string, string>
body?: any
timeout?: number
}| Property | Type | Description |
|---|---|---|
method | string | HTTP method |
url | string | Full URL to request |
headers | Record<string, string>? | Request headers |
body | any? | Request body (auto-serialized to JSON) |
timeout | number? | Request timeout in ms |
Response
interface FetchResponse<T = any> {
status: number
headers: Record<string, string>
data: T
}| Field | Type | Description |
|---|---|---|
status | number | HTTP status code |
headers | Record<string, string> | Response headers |
data | T | Parsed response body |
POST with body
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:
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}`,
},
})