Build
Library
Share code between functions with library modules — API clients, validation, business rules and helpers.
The Library holds code modules that every function of the same language can import. Write a helper once instead of copying it into every function.
#Use a module
JavaScript — lib/pricing.js
export function priceFor(items) {
return items.reduce((sum, i) => sum + i.price * i.qty, 0);
}JavaScript — function
import { priceFor } from './lib/pricing.js';
export async function handler(req) {
return { status: 200, body: { total: priceFor(req.body.items) } };
}Python
# lib/pricing.py
def price_for(items):
return sum(i["price"] * i["qty"] for i in items)
# function
from lib.pricing import price_for#What belongs in the library
- Clients for third-party APIs, with auth and retries.
- Validation and parsing.
- Business rules — pricing, permissions, formatting.
- Helpers around storage.
- Constants shared by several functions.
Modules can import packages, the Wisp SDK and each other. A module isn't callable over HTTP and has no handler.
#Changes rebuild every function
Editing a module rebuilds every function of that language in the draft. Test at least one function that uses it before publishing.