Accepting Inputs

Accepting Inputs

The first argument to your handler function is the inputs object. It is passed as a parameterized object to your handler, and it is optional. The inputs object can contain anything—strings, booleans, arrays, and even other objects—as long as it's serializable as JSON (which the exception of Dates, which Zipper handles specially for you).

Let’s look at a simple "hello world" applet that accepts a string for who you are greeting.

export async function handler(inputs: { name: string }) {
  return `Hello, ${inputs.name}!`;
}

Alternatively, you can define your inputs as a type (which is typcially named Inputs by convention) and pass it to the handler function.

type Inputs = {
  name: string;
};
 
export async function handler(inputs: Inputs) {
  return `Hello, ${inputs.name}!`;
}

Based on type definitions through TypeScript, Zipper will generate a UI form so that your applet users can supply input values.

Zipper generates the UI form

When you run your applet, you can supply your inputs manually in the browser, through query parameters, or as a data payload in a POST request. See Basic Concepts for details.

Input types

Zipper supports several different input types.

string

type Inputs = {
  name: string;
};

String input

Date

type Inputs = {
  date: Date;
};

Date input

boolean

type Inputs = {
  bool: boolean;
};

Boolean input

number

type Inputs = {
  numeric: number;
};

Number input

enum

enum Directions {
  UP = 'up',
  DOWN = 'down',
}
 
type Inputs = {
  directions: keyof typeof Directions;
};

enum input

union of literal types

type Inputs = {
  fruit: 'apple' | 'orange';
};

union of literal types input

array of literal types

type Inputs = {
  directions: ('up' | 'down' | 'left' | 'right')[];
};

union of literal types input

array, object, or any

If you use a more generic type like array, object, or any (or a type Zipper doesn’t know yet), then Zipper will default to a generic text input that can take JSON.

type Inputs = {
  anyType: any;
};

any input

Sign inJoin the beta
© 2023 Zipper, Inc. All rights reserved.