This guide demonstrates how to use a CUE workflow command to fetch some JSON over HTTP.
It is converted from its JSON representation into data, which is then used by the workflow command.
a_tool.cue
package example
import (
"tool/http"
"tool/cli"
"encoding/json"
)
command: info: {
fetch: http.Get & {
url: "https://proxy.golang.org/cached-only/cuelang.org/go/@v/v0.8.2.info"
}
display: cli.Print & {
_data: #info & json.Unmarshal(fetch.response.body)
text: "CUE version \(_data.Version) was released with commit hash \(_data.Origin.Hash)"
}
}
// The data received is validated against this schema. This is good practice,
// but is not required before using the data.
#info: {
Version!: string
Origin?: {
Hash!: string
...
}
...
}
TERMINAL
$ cue cmd info
CUE version v0.8.2 was released with commit hash 596c99191ad1eb7c39d547e59bc7085751d7952b
Related content
- Reference: cue help commands – CUE workflow commands
- Go API:
tool/http
– make HTTP requests in workflow commands - Go API:
encoding/json
– convert data to and from its JSON representation - Go API:
tool/cli
– interact with the user’s terminal in workflow commands