Call your plugin from a terminal
Run one of your plugin's RPC methods on the running engine with npx @conciv/cli plugin call, and read its JSON answer.
npx @conciv/cli plugin call runs one of your plugin's RPC methods on the running engine and prints the answer. Use
it to try a method while you write it, or to call your plugin from a script.
Call a method
Start your dev server, then run the method from your project folder:
npx @conciv/cli plugin call plant-shelf count --data '{"plant": "fern"}'{"ok": true, "data": {"plant": "fern", "count": 3}}A few things to notice:
plant-shelfis the id of the plugin's RPC contract.countis the method. See Share an RPC method.--datais the method's input, as JSON. Leave it out for a method that takes no input.-dis the short form.- The answer is one line of JSON. The command exits
0on success.
The plugins conciv ships answer the same way. This reads the test runner's last result:
npx @conciv/cli plugin call test-runner statusRead a failure
A failure prints ok: false and an error. The command exits 1. A method's own error carries its name as
type, with its message and data. Here the shelf has no ferns left:
npx @conciv/cli plugin call plant-shelf sell --data '{"plant": "fern"}'{
"ok": false,
"error": {
"kind": "user",
"message": "fern is sold out",
"code": "PLUGIN_RPC",
"type": "sold-out",
"data": {"plant": "fern"}
}
}The engine answers some errors itself:
rpc.unavailable: no plugin registered that contract id.rpc.method_not_found: the contract has no such method.rpc.invalid_input: the data does not match the method's input.rpc.internal: the method threw. The code isPLUGIN_RPC_INTERNAL.rpc.invalid_output: the method returned something its output schema refuses. The code isPLUGIN_RPC_INTERNAL.
The command refuses data that is not JSON before it sends anything:
{
"ok": false,
"error": {
"kind": "user",
"message": "--data is not JSON: {plant: fern}",
"hint": "pass the method's input as JSON, for example --data '{}'"
}
}Next steps
- Share an RPC method: write the methods this command calls.
- CLI reference: every conciv command.