Calling Procs

Procs are mounted at an endpoint in the http api. Each proc is called with input, applies a behavior and responds with a result. Client libraries abstract the api into native objects and methods, allowing remote proc calls to sit alongside your local code.

Here's a simple example that uses the type.string.truncate endpoint to shorten a string.

something went wrong :(
Truncating a string to a specific length
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
client.type.string.truncate.call(
  "foobar", length: 3
)
client.type.string.truncate.call(
  "foobar", {length: 3}
);
curl "https://proc.run/type/string/truncate?length=3" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/json" \
--data '"foobar"'
 

foo

Proc defines dozens of endpoints to support all kinds of use-cases—explore them in packages.

Passing Procs as Values

Procs can be passed as input or as argument values to other proc calls. Building on the truncation example above, we can turn the call to type.string.truncate into a callable value, then pass it as input to keyv.set to store the truncated value in the key-value store.

something went wrong :(
Storing a truncated value
Setup
require "proc"

client = Proc.connect("PROCAUTH")
const Proc = require("@proc.dev/client");
const client = Proc.connect("PROCAUTH");
authorization=PROCAUTH
truncated = client.type.string.truncate(
  "foobar", length: 3
)

client.keyv.set.call(
  bucket: "vb683ee3", value: truncated
)
let truncated = client.type.string.truncate(
  "foobar", {length: 3}
);

client.keyv.set.call(
  undefined, vb683ee3
);
curl "https://proc.run/keyv/set?bucket=vb683ee3" --silent \
--header "authorization: bearer $authorization" \
--header "content-type: application/vnd.proc+json" \
--header "accept: text/plain" \
--data '[["$$", "value", ["{}", ["()", "type.string.truncate", [">>", ["%%", "foobar"]], ["$$", "length", ["%%", 3]]]]]]'
 

true

Using with instead of call builds a callable value that is evaluated within proc rather than on the client.


Stuck? Want to chat about an idea? Join the community on Discord.