Lifecycle
1
Write
Write a script that starts with a
contract declaration giving its path, name, optional version and parameters. See Writing contracts below.2
Save
Send the script to
POST /contracts. The server checks that it parses and stores it.3
Invoke
Post JSON parameters to
/run/<path>/<Name>. See Invoking contracts.4
Evolve
Contracts are immutable. To change one, save a new version. See Versioning.
Writing contracts
A contract declaration has a path, a name, an optional version and an optional parameter list:Path and name
The path is a dot-separated prefix that groups related contracts, and the name is the final segment. Together they identify the contract. Two contracts can share a name if their paths differ:Parameters
Parameters arename: type pairs, separated by commas, with an optional trailing comma. Any type can be used, including decimal(p, s) and list types.
- Parameter names must be unique.
- A contract without parameters leaves out the parentheses. Empty parentheses,
(), are an error. - Parameters are
constinside the body. You can’t reassign them, but you can modify the contents of object and list parameters.
Body
The body is the same as any script body: variables, resources,if statements and a return. The returned value becomes the returnValue of each invocation.
Contracts compared to requests
Sending a contract script to
POST /run, or a request script to POST /contracts, is rejected with an InvalidScript error.