Key Value API
1
4fbf02fc-0329-4291-aac3-0143969167c4
Promise API
2
4fbf02fc-0329-4291-aac3-0143969167c4
Worker API
8
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Token API
7
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Template API
6
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Project policy API
5
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Project grant API
4
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Project API
3
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Login API
2
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Account API
1
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Breaking changes August 2023
1
726cfb0b-bffe-41ba-98b4-94069569ec3c
Overview
0
726cfb0b-bffe-41ba-98b4-94069569ec3c
Tier 4 languages
4
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
Python
4
54bda586-0bf3-430e-93e5-6d8c578372bd
Overview
0
ac8f610e-7e8f-465d-9e32-4b6ae0aba3b5
Overview
0
0f58ad57-8cb7-4a64-8aed-c7bea90c37f9
Overview
0
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
Overview
0
54bda586-0bf3-430e-93e5-6d8c578372bd
Overview
0
9b92ca64-009f-47e8-9457-b544f786d8af
Quickstart
2
1d167981-dd90-40ab-8023-3b2013ceb5c5
Overview
0
1aa11fd4-1dcf-4c87-8b46-5c15ca815d61
Overview
0
4fbf02fc-0329-4291-aac3-0143969167c4
Overview
0
d0be080a-56f4-481a-91d3-ba7d30c144f4
Common tooling
1
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
C
3
54bda586-0bf3-430e-93e5-6d8c578372bd
Go
2
54bda586-0bf3-430e-93e5-6d8c578372bd
Grain
3
9b92ca64-009f-47e8-9457-b544f786d8af
Swift
1
9b92ca64-009f-47e8-9457-b544f786d8af
C#
3
9b92ca64-009f-47e8-9457-b544f786d8af
Zig
2
9b92ca64-009f-47e8-9457-b544f786d8af
Rust
1
54bda586-0bf3-430e-93e5-6d8c578372bd
Overview
0
fc0b5887-cca5-4261-b6b7-73711f6f23b0
Overview
0
62133a19-c114-4a29-a74b-f986d118e157
Why Golem?
1
1d167981-dd90-40ab-8023-3b2013ceb5c5
Overview
0
1d167981-dd90-40ab-8023-3b2013ceb5c5
API Gateway
308adf1f-525e-460e-81c9-6ea00d1dbca4
d0be080a-56f4-481a-91d3-ba7d30c144f4
4
Release notes
726cfb0b-bffe-41ba-98b4-94069569ec3c
d0be080a-56f4-481a-91d3-ba7d30c144f4
9
Component interface
ac8f610e-7e8f-465d-9e32-4b6ae0aba3b5
d0be080a-56f4-481a-91d3-ba7d30c144f4
7
Getting Started
1d167981-dd90-40ab-8023-3b2013ceb5c5
d0be080a-56f4-481a-91d3-ba7d30c144f4
1
Building Components
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
d0be080a-56f4-481a-91d3-ba7d30c144f4
2
Tier 2 languages
54bda586-0bf3-430e-93e5-6d8c578372bd
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
2
Promises
62133a19-c114-4a29-a74b-f986d118e157
d0be080a-56f4-481a-91d3-ba7d30c144f4
3
Tier 3 languages
9b92ca64-009f-47e8-9457-b544f786d8af
03501aa5-572b-4129-aa0a-9e9fe9f5d3fc
3
Golem CLI
1aa11fd4-1dcf-4c87-8b46-5c15ca815d61
d0be080a-56f4-481a-91d3-ba7d30c144f4
4
REST API
fc0b5887-cca5-4261-b6b7-73711f6f23b0
d0be080a-56f4-481a-91d3-ba7d30c144f4
5
Runtime API
4fbf02fc-0329-4291-aac3-0143969167c4
d0be080a-56f4-481a-91d3-ba7d30c144f4
6
FAQ
0f58ad57-8cb7-4a64-8aed-c7bea90c37f9
d0be080a-56f4-481a-91d3-ba7d30c144f4
7

Overview

ac8f610e-7e8f-465d-9e32-4b6ae0aba3b5

This section describes how your Golem Template’s public interface is defined using the WASM component model and how is it mapped into the Golem API.

The page is divided into two major sections by tiers, as the ability to define your template’s interface is one of the primary differentiators between our different language tiers. Read the Building Templates page for more information.

This page will use Golem CLI parameter names when talking about how to invoke functions, but the same rules apply when using the REST API too.

Tier 2 languages

Tier 2 languages use the WASM component model’s tooling to define their interface using WIT files. Please read the official design document of the WIT format to learn what it is capable of.

For each tier 2 language there is a binding generator tool that takes the WIT definition and generates the appropriate binding code in the given guest language. Read Building Templates for more information about how these tools work.

The WIT definition is also embeded in the compiled WASM that you upload to Golem Cloud. This is how Golem knows what the exported functions are, and it can validate the provided parameters to make sure they have the correct type.

Function names

This section explains how you can map the exported function names from your WIT definition to fully qualified names to be passed in the --function parameter when invoking an instance.

The component you define has a WIT package, specified in the top of your WIT definition.

For example if you generated your code using golem new and did not specify a custom package name, it will be:

package golem:component

You can have any other pair of names following the above syntax.

The WIT definition should contain a single world (otherwise the world to be used have to be specified for the tools used during compilation). The name of this world does not matter for Golem - it won’t be part of the function’s fully qualified name.

For example it can be:

world my-component-world {

// ...

}

In this world you can either export

  • one or more interface
  • or one or more functions directly

The following example demonstrates both:

package golem:component



interface api {

record product-item {

product-id: string,

name: string,

price: float32,

quantity: u32,

}



add-item: func(item: product-item) -> ()

remove-item: func(product-id: string) -> ()

}



world my-component-world {

export api

export dump: func() -> result<string, string>

}

The name of the interface(s) and function(s) are completely user defined, there are no rules to follow other than the syntax rules of WIT itself.

In the above example we have 3 exported functions and we can refer to them in the --function parameter with the following fully qualified names, consisting of the package name and the exported path:

  • golem:component/api/add-item
  • golem:component/api/remove-item
  • golem:component/dump

Parameters and results

This section defines the mapping from the different types you can use or define in your WIT definition and the JSON you pass to the --parameters parameter of the invocation and see as your invocation’s result.

When invoking a function, the JSON passed to --parameters always has to be a JSON array. Each element of this array corresponds to one parameter of the function. So to call a function without any parameters pass an empty array ([]). The result of a function invocation is also a JSON.

The following table maps types you can use in WIT to their JSON encoding:

boolJSON booleanPrimitive boolean type
u8JSON numberUnsigned 8-bit integer
s8JSON numberSigned 8-bit integer
u16JSON numberUnsigned 16-bit integer
s16JSON numberSigned 16-bit integer
u32JSON numberUnsigned 32-bit integer
s32JSON numberSigned 32-bit integer
u64JSON numberUnsigned 64-bit integer
s64JSON numberSigned 64-bit integer
float32JSON number32-bit floating point number
float64JSON number64-bit floating point number
charJSON numberASCII character
stringJSON stringString
<t1, t2, ...>JSON array of the items:
[v1, v2, …]
Tuple of types t1, t2, …
list<t>JSON array of the items:
[item1, item2, …]
List of items of type t
option<t>null if not defined
the inner value if defined
An option of type t
result<t, e>Object with either an ok or an err field:
{ "ok": ... }
{ "err": ... }


If t or e is unit (_ in WIT) then use null in the JSON, for example { "ok": null }.
Type representing either a success of type t or a failure of type e
handlenot supported yet
idnot supported yet
recordJSON object where for each record field there is a field with the same name.Record containing a series of named fields.
variantJSON object with a single field that has the name of one of the variants. For example:
{ "child": 10 }
Variant that can be one of the specified types, discriminated by a case name.
enumJSON string holding the name of the enum, for example "low"Enum is a set of possible named values
flagsA JSON array of stringsSet of possible name values, where you can select more than one of them.

Tier 3 languages

For Tier 3 languages you cannot define more than one function to be exported. The function that Golem will run is your program’s main function, without passing any arguments or getting any result values.

Function names

The function name for tier 3 languages that you need to pass to the --function parameter of Golem CLI is always:

  • wasi:cli/run/run

Parameters and results

As you cannot define any parameter or result types in tier 3 the only option is to use the stdio mode or the stdio event loop mode.

This is enabled in the Golem CLI using the --use-stdio or --use-stdio-eventloop commands when invoking an instance.

Once it is enabled, the JSON you pass to the --parameters parameter will be directly available to read from the worker’s standard input, and Golem expects the run function to write a result JSON to the standard output.

No further type checking is performed, but both the input and the output is expected to be JSONs.

When using an event loop the worker is expected to run an infinite loop in which each iteration reads a single line and parses it as JSON, and outputs a single line JSON as the invocation’s results before reading the next one.