Automatic Inference of required inputs for API Endpoint based on Rib script
Now that, we registered API definitions, and deployed them. As you have seen Rib script in the response field or worker name may try to look up values from the request context. This is auto documented and you can see them in the response when you register an API definition Golem Console provides a more user-friendly way to see these inputs.
Here is a sample response when you register an API definition, where it holds the required data in the input http request.
{
"id": "my-shopping-cart-v1",
"version": "0.0.4",
"routes": [
{
"method": "Get",
"path": "/v4/{user-id}/get-cart-contents",
"binding": {
"componentId": {
"componentId": "dba38841-013a-49fa-a1dc-064949832f0c",
"version": 0
},
"workerName": "let user: u64 = request.path.user-id;\n\"my-worker-${user}\"",
"idempotencyKey": null,
"response": "let result = golem:it/api.{get-user-name}();\n{status: 200u64, body: result}",
"responseMappingInput": {
"types": {
"request": {
"type": "Record",
"fields": [
{
"name": "path",
"typ": {
"type": "Record",
"fields": [
{
"name": "user-id",
"typ": {
"type": "U64"
}
}
]
}
}
]
}
}
},
"workerNameInput": {
"types": {
"request": {
"type": "Record",
"fields": [
{
"name": "path",
"typ": {
"type": "Record",
"fields": [
{
"name": "user-id",
"typ": {
"type": "U64"
}
}
]
}
}
]
}
}
},
"responseMappingOutput": {
"type": "Record",
"fields": [
{
"name": "status",
"typ": {
"type": "U64"
}
},
{
"name": "body",
"typ": {
"type": "Str"
}
}
]
},
"idempotencyKeyInput": null
}
}
],
"draft": true,
"createdAt": "2024-10-31T07:40:16.239763054Z"
}
In the above response, you can see the responseMappingInput
field which holds the required input for the Rib script in the response field,
as well as workerNameInput
which holds the required input for the Rib script in the workerName field.
Automatic inference of output types for API Endpoint based on Rib script
In the same example above, it infers the output types of the response mapping Rib script as well. In near future, these auto inferred inputs and outputs can be used to generate OpenAPI spec for the API that is deployed in Golem.