Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/iii-hq/sdk/llms.txt

Use this file to discover all available pages before exploring further.

The III SDK provides types for handling HTTP API requests and responses, including support for streaming data.

ApiRequest

Represents an incoming HTTP request with parsed parameters and body.
type ApiRequest<TBody = unknown> = {
  path_params: Record<string, string>
  query_params: Record<string, string | string[]>
  body: TBody
  headers: Record<string, string | string[]>
  method: string
}

Fields

path_params
object
required
Path parameters extracted from the URL pattern (e.g., /users/:id{ id: "123" }).
query_params
object
required
Query string parameters. Values can be strings or arrays for repeated parameters.
body
TBody
required
The parsed request body. Type can be specified via generic parameter.
headers
object
required
HTTP headers. Values can be strings or arrays for repeated headers.
method
string
required
HTTP method (GET, POST, PUT, PATCH, DELETE, etc.).

ApiResponse

Represents an HTTP response to be sent back to the client.
type ApiResponse<
  TStatus extends number = number,
  TBody = string | Buffer | Record<string, unknown>
> = {
  status_code: TStatus
  headers?: Record<string, string>
  body?: TBody
}

Fields

status_code
number
required
HTTP status code (200, 404, 500, etc.).
headers
object
Response headers to include.
body
TBody
Response body. Can be a string, Buffer, or object (automatically JSON serialized).

HttpRequest

For streaming HTTP handlers, includes access to the request body stream.
type HttpRequest<TBody = unknown> = {
  path_params: Record<string, string>
  query_params: Record<string, string | string[]>
  body: TBody
  headers: Record<string, string | string[]>
  method: string
  request_body: ChannelReader
}

Additional Fields

request_body
ChannelReader
required
Stream reader for accessing the raw request body as chunks.

HttpResponse

Streaming response writer for HTTP handlers.
type HttpResponse = {
  status: (statusCode: number) => void
  headers: (headers: Record<string, string>) => void
  stream: NodeJS.WritableStream
  close: () => void
}

Methods

status
function
required
Set the HTTP status code for the response.
headers
function
required
Set response headers.
stream
WritableStream
required
Writable stream for sending response body chunks.
close
function
required
Close the response stream and complete the HTTP response.

Usage Examples

Simple API Handler

type CreateUserRequest = {
  name: string
  email: string
}

iii.registerFunction(
  { id: 'api::users::create' },
  async (req: ApiRequest<CreateUserRequest>): Promise<ApiResponse<201, { id: string }>> => {
    const user = await db.users.create(req.body)
    
    return {
      status_code: 201,
      headers: { 'Content-Type': 'application/json' },
      body: { id: user.id }
    }
  }
)

Streaming Response

import { http } from '@iii/sdk'

const handler = http(async (req: HttpRequest, res: HttpResponse) => {
  await res.status(200)
  await res.headers({ 'Content-Type': 'text/plain' })
  
  res.stream.write('Starting stream...\n')
  
  for (let i = 0; i < 10; i++) {
    await new Promise(resolve => setTimeout(resolve, 100))
    res.stream.write(`Chunk ${i}\n`)
  }
  
  res.close()
})

iii.registerFunction({ id: 'api::stream' }, handler)

Build docs developers (and LLMs) love