Barua /Docs/Functions
Early access

Barua Functions

Paste a GitHub repository written in Rust or Go. We build it to WebAssembly and run it next to your data. You get a URL, logs, and a place for your environment. Nothing to install.

Deploy

Open fn.barua.app, paste the repository's URL, press Deploy. The build log appears as it happens — the same output you would see in your own terminal — and when it finishes the function is live at https://fn.barua.app/<name>.

Try it with nassdaq/hello-barua-fn: Rust at the root, the same function in Go under go/. On our box it builds in about four seconds.

What a function is

A program that reads its input on stdin and prints its answer on stdout. That is the whole contract — no framework, no SDK, no special types. The body of the request is the input; whatever you print is the response.

Rust

use std::io::{self, Read, Write};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).ok();
    let greeting = std::env::var("GREETING").unwrap_or("Hello".into());
    write!(io::stdout(), "{{\"message\":\"{}, {}!\"}}", greeting, input.trim()).ok();
}

Go

func main() {
    input, _ := io.ReadAll(os.Stdin)
    greeting := cmp.Or(os.Getenv("GREETING"), "Hello")
    fmt.Printf("{\"message\":\"%s, %s!\"}", greeting, strings.TrimSpace(string(input)))
}

What the repository needs. Rust: a Cargo.toml with a [package] and a src/main.rs. Go: a go.mod and a main.go. Optionally a barua.json so the API tab can list what it does. Nothing else is read - no Dockerfile, no server, no .env. The program reads stdin, prints stdout, exits 0. Drawn, with the smallest working examples →

We tell the language from the repository: a Cargo.toml is Rust, a go.mod is Go. No toolchain on your side, and no .wasm to look at — the build is ours.

Your URL

curl -X POST https://fn.barua.app/hello-barua-fn --data '{"name": "Asha"}'
# {"message":"Hello, Asha!","lang":"rust","greeting_from_env":false}

Environment

The Environment tab holds KEY=value pairs. Save them and the next call sees them — std::env::var in Rust, os.Getenv in Go. Keys and secrets belong here, not in the repository.

Database

A function has no network of its own, so it asks the host. Put a Postgres URL in DATABASE_URL on the Environment tab - a Barua database in the same region answers in a few milliseconds, since the function and the database share a box - and call it from your code. The host keeps the connection warm, so a fresh instance per call costs nothing extra; each call shows its queries in the activity log.

Rust - the barua-fn crate

[dependencies]
barua-fn = { git = "https://github.com/nassdaq/barua-fn-rs" }

use barua_fn::{execute, query};
use serde_json::json;

execute("create table if not exists visits (who text, at timestamptz default now())", &[])?;
execute("insert into visits (who) values ($1)", &[json!("Asha")])?;
let rows = query("select count(*)::int as n from visits", &[])?;

Any statement works - SELECT, INSERT … RETURNING, migrations - with $1 parameters. Rows come back as JSON objects keyed by column. A worked example lives in hello-barua-fn/db: deploy it with the folder set to db. Go support for the same host call is next.

Logs

Two kinds. The build log is everything the compiler said, kept with the deployment. The call log records each request: when, status, how long, exit code, bytes in and out, and anything the function wrote to stderr — so a failing call explains itself.

Changing it

Push to GitHub, then press Deploy again with the same name. The moment the build finishes the URL serves the new code; a failed build never replaces a working function.

Limits

Access

Functions is in early access. The page asks for an access key once and keeps it in your browser; ask us for one. The URLs of your functions need no key — they are there to be called by your app and your users.

Barua Functions · fn.barua.app · Tasks Example repository Built in Dar es Salaam