Formulate

API

Use the Formulate API to build forms using nothing but code.

The code you provide must export a single async function, like so:

export default async function() {

}

You can access API methods/functions using the form global. This is also aliased to f and formulate, so these three calls are equivalent:

await f.short("Hello! What is your name?");
await form.short("Hello! What is your name?");
await formulate.short("Hello! What is your name?");

Answers are collected automatically and persisted when the user has made it to the end of the form. Use the ignore option to disable answer collection for certain questions.

All API calls that return a Promise must be awaited. The Promise is typically resolved when the user has submitted an answer.

API Functions

The API provides functions in a few different categories:

  • Questions: Present the user with a question and collect an answer
  • HTTP: Fetch data from a remote server at runtime
  • Logging: Log data to the browser console
  • Query Params: Read key-value pairs from the browser's query string
  • Utilities: Use the Lodash utility library when the JS standard library isn't sufficient

And here are a few other related features:

  • Banners: Display an image/video/GIF alongside a question
  • Custom Email: Customize the email notification you'll receive from within the form
  • Typings: Typescript d.ts definitions for the entire API