Verbs
Defining Verbs
To declare a Verb, write a normal Go function with the following signature, annotated with the Go comment directive //ftl:verb
:
//ftl:verb
func F(context.Context, In) (Out, error) { }
eg.
type EchoRequest struct {}
type EchoResponse struct {}
//ftl:verb
func Echo(ctx context.Context, in EchoRequest) (EchoResponse, error) {
// ...
}
To declare a Verb, write a normal Kotlin function with the following signature, annotated with the Kotlin annotation @Verb
:
@Verb
fun F(Context, In): Out { }
eg.
data class EchoRequest
data class EchoResponse
@Verb
fun echo(ctx: Context, request: EchoRequest): EchoResponse {
// ...
}
By default verbs are only visible to other verbs in the same module.
Calling Verbs
To call a verb use ftl.Call()
. eg.
out, err := ftl.Call(ctx, echo.Echo, echo.EchoRequest{})
To call a verb, import the module's verb client, add it to your verb's signature, then call()
it. eg.
import ftl.time.TimeClient
@Verb
fun echo(req: EchoRequest, time: TimeClient): EchoResponse {
val response = time.call()
// ...
}
val response = time.call()