SDK

Overview

The formr SDK is a universal JavaScript/TypeScript library that works in Node.js, Edge runtimes, and browsers. It provides a simple interface for interacting with the Form Platform API.

Installation

npm install formr
# or
pnpm add formr
# or
yarn add formr

Quick Start

Server-side

import { Formr } from 'formr';

const formr = new Formr({ 
  apiKey: process.env.FORMR_KEY 
});

// Fetch form schema
const form = await formr.forms.get('contact-form');

// Submit form
await formr.forms.submit('contact-form', { 
  email: 'user@example.com',
  name: 'John Doe'
}, { 
  idempotencyKey: req.headers['x-idempotency-key'] 
});

// List responses (server)
const { items, nextCursor } = await formr.responses.list({ 
  formId: 'contact-form' 
});

Client-side

Configuration

API Methods

Forms

formr.forms.get(formId)

Fetch a form schema.

formr.forms.create(form)

Create a new form (requires API key).

formr.forms.update(formId, form)

Update an existing form (requires API key).

formr.forms.submit(formId, data, options?)

Submit form data.

Parameters:

  • formId: Form ID

  • data.answers: Form field answers

  • data.sessionId: Session ID (optional)

  • options.idempotencyKey: Idempotency key (optional)

Responses

formr.responses.list(params)

List form responses (requires API key).

Parameters:

  • formId: Filter by form ID

  • limit: Limit results (default: 50)

  • cursor: Pagination cursor

formr.responses.get(responseId)

Get a specific response (requires API key).

Webhooks

Formr.webhooks.verify(signature, rawBody, secret)

Verify webhook signature.

Error Handling

The SDK throws FormrError for API errors:

Features

  • Auth: API key based authentication

  • Automatic Retries: Exponential backoff retry logic

  • Idempotency: Idempotency key support

  • Webhook Verification: HMAC SHA-256 signature verification

  • TypeScript: Full TypeScript support

  • Tree-shakeable: ESM-only, sideEffects: false

  • Universal: Works in Node.js, Edge runtimes, and browsers

Examples

Next.js API Route

Webhook Handler

Next Steps

  • Development Tools - Other development tools

  • React Components - React components

  • API Reference - Complete API documentation

Last updated