Getting started
fncosmos is in early access: things work, and things will change.
1. Create an account
Sign up with your email.
2. Install the CLI
On macOS and Linux (x86-64):
curl -fsSL https://fncosmos.com/install.sh | sh It goes in ~/.fncosmos/bin. fncosmos upgrade installs new versions, and
checks each one's signature first, and fncosmos uninstall removes it all. Windows and Linux on ARM are coming.
To build operations you also need Rust and its WebAssembly target. Your code is compiled on your machine; only the result is uploaded.
rustup target add wasm32-wasip2 3. Sign in and start a project
fncosmos login
cd my-app
fncosmos init login shows a link and a code. Open the link, check the code, and approve it. It works
over SSH too. init creates a project named after the folder (it's yours) and a fncosmos/ folder with an example operation.
4. Write operations
fncosmos/src/lib.rs starts with one. An operation is a Rust function, and what
triggers it:
use fncosmos_sdk::prelude::*;
#[derive(Deserialize, JsonSchema)]
struct Hello {
name: String,
}
fncosmos_sdk::export![
operation("hello")
.http("GET /hello/{name}")
.public()
.handler(|ctx, args: Hello| {
ctx.log(format!("greeting {}", args.name));
Ok(format!("Hello, {}!", args.name))
}),
]; 5. Run it
fncosmos dev # deploys now and on every save
fncosmos run my-app:hello name=ada # in another terminal
curl https://api.fncosmos.com/p/my-app/hello/ada fncosmos dev builds on your machine, uploads the result, and prints each run as it
finishes. A build that fails shows the compiler's error and keeps the last good version
running.
6. Call it from your frontend
Every deploy writes a typed client to fncosmos/_generated/client.ts, from your Rust
types:
import { createClient } from "../fncosmos/_generated/client";
const api = createClient({ baseUrl: "https://api.fncosmos.com" });
const greeting = await api.myApp.hello({ name: "ada" }); // string More docs are on the way.